Fixes invalid error message "id [object Object]
is nullish". Now displays actual object contents.
No breaking changes. Just a version bump and minor tweaks required for gatsby@^3.0.0
compatibility.
New debugging utility allowing you to dump compiled queries to disk. Example usage:
const { writeCompiledQueries } = require("gatsby-graphql-source-toolkit")
// Step4. Compile sourcing queries
const documents = compileNodeQueries({
schema,
gatsbyNodeTypes,
customFragments: fragments,
})
// Write compiled queries for debugging
await writeCompiledQueries(`./sourcing-queries`, documents)
For each node type it will create a Type.graphql file with full GraphQL queries for this node type. Run those queries against your remote GraphQL endpoint manually for troubleshooting.
Now whenever GraphQL response contains non-fatal errors, they will be displayed in the console (but sourcing process will continue).
The following now works as expected:
const execute = createDefaultQueryExecutor(`https://www.example.com/graphql`, {
headers: {
"Accept": "application/json",
},
})
Added new experimental tool compileGatsbyFragments
. Use it to compile custom source fragments to
Gatsby fragments. See README.md for details.
- be smarter when adding a
__typename
field (see #11) - support variables within input objects (see #13)
- support lists with a single value in
NODE_
queries (see #14)
Now you can do things like this:
fragment User on User {
dateOfBirth {
...UtcTime
}
}
fragment UtcTime on DateTime {
utcTime
}
Before v0.5.0 this set of fragments would have thrown an error because only fragment on Node types were supported. Now nested fragment spreads on non-node types are supported as well.
Before this release the toolkit was incorrect fragments for the following schema:
type Foo {
foo: String
}
type Bar {
fooList: [Foo!]!
}
Before this release it compiled:
fragment Bar on Bar {
fooList {
foo
}
}
After this release it correctly compiles:
fragment Bar on Bar {
fooList {
remoteTypeName: __typename
foo
}
}
This is important for abstract types to resolve specific type when Gatsby runs queries.
Say your remote schema has those types:
interface Iface {
foo: String
}
type Foo implements Iface {
foo: String
}
Before this version the following fragment would add the field foo
to Gatsby version of your remote Iface
type:
fragment FooFragment on Foo {
foo
}
After this version it will not. Only the fragment on Iface
specifically will add it:
fragment IfaceFragment on Iface {
foo
}
Update your node type configs like this to account for this change:
const gatsbyNodeTypes = [
{
remoteTypeName: `Post`,
- remoteIdFields: [`__typename`, `id`],
queries: `
query LIST_POSTS {
- posts(limit: $limit offset: $offset)
+ posts(limit: $limit offset: $offset) {
+ ..._PostId_
+ }
}
+ fragment _PostId_ on Post {
+ __typename
+ id
+ }
`,
},
]
Note: the name of the fragment id could be anything but try to use a
unique one to avoid possible conflicts with custom fragments
(e.g. in the example above we add _
as a prefix and a suffix)
This has several advantages:
-
Source queries can be tested directly against the API (they are now valid queries that fetch node IDs)
-
This format helps to express complex ids (wasn't possible before), e.g.:
- Contentful puts id in nested object
sys
; - Drupal has a composite id:
{ entityId, entityLanguage { id } }
- Contentful puts id in nested object
Diff of function output for various internal Gatsby fields:
fragment SomeRemoteType on SomeRemoteType {
remoteId: id
remoteInternal: internal
remoteParent: parent
remoteChildren: children
- fields {
+ remoteFields: fields {
someField
}
}