Appearance
Request Lifecycle
There are various steps that a GraphQL query goes through. Let's look at what happens when you do await useGraphqlQuery('myQuery') in a component:
Client (Request)
- Call
useGraphqlQuery() - If client options are defined, buildClientContext() is called
- If client fetch options are defined, the
onRequestfetch interceptor is called $fetch()request is started
Server
- The
/api/graphql_middleware/queryserver route handles the request - The
serverOptions.graphqlEndpoint()method is called to determine the URL of the GraphQL server - The
serverOptions.serverFetchOptions()method is called to get the fetch options for the request to the GraphQL server - The fetch request to the GraphQL server is started
- If the request was successful:
- The
serverOptions.onServerResponsemethod is called
- The
- If the request failed:
- The
serverOptions.onServerErrormethod is called
- The
- The response is sent to the client
Client (Response)
- If client fetch options are defined, the
onResponsefetch interceptor is called - The result of the query is returned in the composable