Skip to content

Commit

Permalink
docs: add more info about the differences to GraphQL-JS (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
boopathi authored Sep 14, 2023
1 parent 1612734 commit 6eb03f8
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
45 changes: 45 additions & 0 deletions GraphQL-JS.md
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;
// }
}
};
```
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ code which yields much better performance. `graphql-jit` leverages this behaviou
#### Benchmarks

GraphQL-JS 16 on Node 16.13.0

```bash
$ yarn benchmark skip-json
Starting introspection
Expand All @@ -37,6 +38,8 @@ The goal is to support the [June 2018 version of the GraphQL spec](https://faceb
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`.

More details here - [GraphQL-JS.md](./GraphQL-JS.md)

## Install

```sh
Expand All @@ -58,7 +61,7 @@ type Query {
const resolvers = {
Query: {
hello() {
return new Promise(resolve => setTimeout(() => resolve("World!"), 200));
return new Promise((resolve) => setTimeout(() => resolve("World!"), 200));
}
}
};
Expand Down

0 comments on commit 6eb03f8

Please sign in to comment.