Graphql Extension
-
Good morning, I am working on a quasar project with a graphql api, I installed the app-extension-apollo extension, but I am interested in being able to execute the queries and mutations in .js files and not in .vue files, how can I import the apollo in my .js file so I can do something like apollo.query ()
-
@rainer9202 You will need to import the Apollo Client into your js file.
I created my own Apollo Client boot file and I am using Vuex. Vuex is just a JavaScript file. Not an exact match to what you are doing but should be close enough to get you started. Hope this helps.
Here is how I import the Apollo Client into a Vuex js file.
import gql from 'graphql-tag' import { apolloProvider } from 'boot/apolloClient' import { Notify } from 'quasar' const gqlClient = apolloProvider.defaultClient
This is an example of a query with parameters.
const response = await gqlClient.query({ query: gql` query AllScheduledRecordings( $orderBy: [OrderByFields] $filterBy: [FilterByFields] $between: [BetweenFields] $whereIn: [WhereInField] $page: Page ) { allScheduledRecordings( orderBy: $orderBy filterBy: $filterBy between: $between whereIn: $whereIn page: $page ) { oid name channelOid recurrenceOid channelName filename status startTimeLocal endTimeLocal failureReason eventDetails landscapeUrl posterUrl logoUrl videoFiles { name base dir ext baseURL } } } `, variables: { ...payload } })