forked from graffle-js/graffle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
community-graphql-code-generator.ts
38 lines (33 loc) · 1.19 KB
/
community-graphql-code-generator.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* `graphql-request@^5` supports `TypedDocumentNode`, the typed counterpart of `graphql`'s `DocumentNode`.
*
* Installing and configuring GraphQL Code Generator requires a few steps in order to get end-to-end typed GraphQL operations using the provided `graphql()`.
*
* The complete example is available in the GraphQL Code Generator repository:
*
* @see 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:
*
* @see https://www.the-guild.dev/graphql/codegen/docs/guides/react-vue.
*/
import request, { gql } from '../src/index.js'
// @ts-expect-error todo make this actually work
import { graphql } from './gql/gql'
const endpoint = `https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr`
// todo fixme
// eslint-disable-next-line
const document = graphql(gql`
query getMovie($title: String!) {
Movie(title: $title) {
releaseDate
actors {
name
}
}
}
`)
// Variables are typed!
const data = await request(endpoint, document, { title: `Inception` })
// @ts-expect-error todo make this actually work
console.log(data.Movie) // typed!