forked from graffle-js/graffle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypescript-typed-document-node.ts
More file actions
37 lines (27 loc) · 944 Bytes
/
typescript-typed-document-node.ts
File metadata and controls
37 lines (27 loc) · 944 Bytes
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
import { gql, GraphQLClient, request } from '../src/index.js'
import type { TypedDocumentNode } from '@graphql-typed-document-node/core'
import { parse } from 'graphql'
{
const endpoint = `https://graphql-yoga.com/api/graphql`
const query: TypedDocumentNode<{ greetings: string }, never | Record<any, never>> = parse(gql`
query greetings {
greetings
}
`)
const variables = {}
const data = await request(endpoint, query, variables)
console.log(data.greetings)
}
{
const endpoint = `https://graphql-yoga.com/api/graphql`
const client = new GraphQLClient(endpoint)
const query: TypedDocumentNode<{ greetings: string }, never | Record<any, never>> = parse(gql`
query greetings {
greetings
}
`)
const data = await client.request({ document: query })
// const variables = {}
// const data = await client.request({ document: query, variables: { a: 1 } })
console.log(data.greetings)
}