How to chain two GraphQL queries in sequence using Apollo Client

The props added by your firstQuery component will be available to the component below (inside) it, so you can do something like: export default compose( graphql(firstQuery, { name: ‘firstQuery’ }), graphql(secondQuery, { name: ‘secondQuery’, skip: ({ firstQuery }) => !firstQuery.data, options: ({firstQuery}) => ({ variables: { var1: firstQuery.data.someQuery.someValue } }) }) )(withRouter(TestPage)) Notice that we … Read more

How to send graphql query by postman?

There’s a better way to do it using the REST client Insomnia Docs are here, how to send graphql queries: https://support.insomnia.rest/article/61-graphql Below are the steps for postman Step 1. Run the GraphiQL in Chrome, open the Chrome Dev Console, click the Network tab, and make the query from graphiql, when you make the query, network … Read more

Template literal – getting error from API

The issue is that given some query like “naruto”, your current code results in the following text: media(type:ANIME, search: naruto ) { This is not valid syntax since String literals should be surrounded by double quotes (“). Don’t use string interpolation to provide dynamic values to the query. These should always be expressed as variables … Read more

How to know which fields were requested in a GraphQL query?

You’ll need to parse the info object that’s passed to the resolver as its fourth parameter. This is the type for the object: type GraphQLResolveInfo = { fieldName: string, fieldNodes: Array<Field>, returnType: GraphQLOutputType, parentType: GraphQLCompositeType, schema: GraphQLSchema, fragments: { [fragmentName: string]: FragmentDefinition }, rootValue: any, operation: OperationDefinition, variableValues: { [variableName: string]: any }, } You … Read more

What is the purpose of template literals (backticks) following a function in ES6?

These are tagged template literals. The part before the backpacks is a reference to a function that will be called to process the string. The function is passed the variables (the ${} parts) as arguments as well as the pieces of the string that surround the variables broken into an array. The return value of … Read more