Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(docs): update documentation on GraphQL Code Generator integration #392

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,40 @@ You are free to try using other versions of Node (e.g. `13.x`) with `graphql-req

## Community

#### GraphQL Code Generator's GraphQL-Request TypeScript Plugin
### Get typed GraphQL Queries with GraphQL Code Generator

A [GraphQL-Codegen plugin](https://graphql-code-generator.com/docs/plugins/typescript-graphql-request) that generates a `graphql-request` ready-to-use SDK, which is fully-typed.
`graphql-request@^5` supports `TypedDocumentNode`, the typed counterpart of `graphql`'s `DocumentNode`.

Installing and configuring [GraphQL Code Generator](https://www.the-guild.dev/graphql/codegen) requires a few steps in order to get end-to-end typed GraphQL operations using the provided `graphql()` helper:

```ts
import request from 'graphql-request';
import { graphql } from './gql/gql';

const getMovieQueryDocument = graphql(/* GraphQL */ `
query getMovie($title: String!) {
Movie(title: $title) {
releaseDate
actors {
name
}
}
}
`);


const data = await request(
'https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr',
getMovieQueryDocument,
// variables are type-checked!
{ title: "Inception" }
)

// `data.Movie` is typed!
```
[_The complete example is available in the GraphQL Code Generator repository_](https://github.com/dotansimha/graphql-code-generator/tree/master/examples/front-end/react/graphql-request)

Visit GraphQL Code Generator's dedicated guide to get started: https://www.the-guild.dev/graphql/codegen/docs/guides/react-vue.

## Examples

Expand Down