GraphQL dynamic query building

GraqhQL provides directives for this very purpose. Create a fragment to define common fields, use @include(if: Boolean) and @skip(if: Boolean) directives on that fragment to get dynamic fields. By dynamic fields we mean fields that are known at execution time. According to spec, it is best to avoid manual string interpolation to construct dynamic queries. … Read more

What is the difference between useQuery and useLazyQuery in Apollo graphQL?

When useQuery is called by the component, it triggers the query subsequently. But when useLazyQuery is called, it does not trigger the query subsequently, and instead return a function that can be used to trigger the query manually. It is explained on this page: https://www.apollographql.com/docs/react/data/queries/#manual-execution-with-uselazyquery When React mounts and renders a component that calls the … Read more

React Apollo – Make Multiple Queries

My preferred way is to use the compose functionality of the apollo client (docu). EDIT: If you have more than one query you should name them. So in your case, it could look like this: import React, {Component} from ‘react’ import queries from ‘./queries’ import { graphql, compose } from ‘react-apollo’; class Test extends Component … Read more

Date and Json in type definition for graphql

Have a look at custom scalars: https://www.apollographql.com/docs/graphql-tools/scalars.html create a new scalar in your schema: scalar Date type MyType { created: Date } and create a new resolver: import { GraphQLScalarType } from ‘graphql’; import { Kind } from ‘graphql/language’; const resolverMap = { Date: new GraphQLScalarType({ name: ‘Date’, description: ‘Date custom scalar type’, parseValue(value) { … Read more

GraphQL: Non-nullable array/list

Non-null means exactly what it sounds like — not null. An empty array is not null — it’s still returning a value. Here is a summary table: declaration accepts: | null | [] | [null] | [{foo: ‘BAR’}] ———————————————————————— [Vote!]! | no | yes | no | yes [Vote]! | no | yes | yes … Read more