GraphQL Union and Input Type?
As of September 2017, this is not possible. There is an ongoing discussion around this functionality.
As of September 2017, this is not possible. There is an ongoing discussion around this functionality.
You can pass a variable to your query and use a Directive to fetch a field conditionally, like name @include(if: $shouldFetchName). See the docs for Directives.
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
Yes, this is possible, but not in this form. GraphQL server will reject such query as a field with the same name used multiple times, but with different arguments. You need to use aliases: query { item1: myItem(size: 100, type: 2) { id, name } item2: myItem(size: 150, type: 2) { id, name } item3: … Read more
GraphQL relies on both the server and the client knowing ahead of time what fields are available available for each type. In some cases, the client can discover those fields (via introspection), but for the server, they always need to be known ahead of time. So to somehow dynamically generate those fields based on the … Read more
You have to add id also to the creator field: query getEvent($eventId: ID!) { Event(id:$eventId) { id headline photo location startTime creator { id username photo } } } In general, make sure to add id to all subselections of your queries.
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 GraphQL, fields at each “level” of the request are executed and resolved in parallel. In your example, user and SomeOtherStuff are both fields of the same type (the root Query type) — so they will be resolved at the same time. That means each query essentially is not aware of the other or what … Read more
Some time ago I came up with another solution, which is the same approach like @WuDo suggested. The idea is to flatten the tree on data level using IDs to reference them (each child with it’s parent) and marking the roots of the tree, then on client side build up the tree again recursively. This … Read more
The short answer is: you don’t. The longer answer is that you have to write that code yourself. GraphQL isn’t a database query language like SQL, it’s an application query language. What that means is that GraphQL won’t let you write arbitrary queries out of the box. It will only support the types of queries … Read more