Notable differences between buildSchema and GraphQLSchema?

The buildSchema function takes a schema in SDL (schema definition language) and returns a GraphQLSchema object. Given two identical schemas generated with each method, runtime performance would be the same. Startup time for a server using buildSchema would be slower since parsing the SDL adds an extra step that would not otherwise exist — whether … Read more

In Relay, what role do the node interface and the global ID spec play?

The Node root field, in combination with globally unique IDs, comes into play when Relay needs to refetch an object. Refetching occurs when you call this.props.relay.forceFetch() or when you add fields to the query for an object whose global ID is known because it has already been partially fetched. In cases like these, Relay will … Read more

How to query list of objects with array as an argument in GraphQL

You can definitely query with an array of values! Here’s what the query itself would look like: { events(containsId: [1,2,3]) { … } } And the type would look something like: const eventsType = new GraphQLObjectType({ name: ‘events’, type: // your type definition for events, args: { containsId: new GraphQLList(GraphQLID) }, … }); If you … Read more

How do you prevent nested attack on GraphQL/Apollo server?

As of the time of writing, there isn’t a built-in feature in GraphQL-JS or Apollo Server to handle this concern, but it’s something that should definitely have a simple solution as GraphQL becomes more popular. This concern can be addressed with several approaches at several levels of the stack, and should also always be combined … 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