-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add more info about the differences to GraphQL-JS (#222)
- Loading branch information
Showing
2 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
## Differences to GraphQL-JS | ||
|
||
In order to achieve better performance, the `graphql-jit` compiler introduces some limitations. | ||
The primary limitation is that all computed properties must have a resolver and only these can return a `Promise`. | ||
|
||
JIT treats the Promise objects at non-computed properties as values and does not await them. So, in such cases, the return value in GraphQL-JIT would be `null`, whereas in GraphQL-JS it would be the awaited value of the Promise. | ||
|
||
Note: This is not to be confused with async resolvers. Async resolvers are supported and awaited by both GraphQL-JS and GraphQL-JIT. | ||
|
||
As an example of this limitation, consider the following schema and resolvers: | ||
|
||
```graphql | ||
type Query { | ||
foo: Foo | ||
} | ||
type Foo { | ||
bar: String | ||
} | ||
``` | ||
|
||
```ts | ||
const resolvers = { | ||
Query: { | ||
// Promise returning functions are supported in both GraphQL-JS and GraphQL-JIT | ||
async foo() { | ||
await Promise.resolve(); | ||
|
||
return { | ||
// The following Promise is not supported by GraphQL-JIT | ||
// without a resolver defined for bar | ||
// like the commented out resolver below | ||
bar: Promise.resolve("bar") | ||
}; | ||
} | ||
}, | ||
Foo: { | ||
// An example resolver that would make GraphQL-JIT | ||
// await the Promise at value bar. | ||
// | ||
// bar(parent) { | ||
// return parent.bar; | ||
// } | ||
} | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters