Skip to content

Commit 961251f

Browse files
committed
Update typescript-graphql-request example
1 parent ef28588 commit 961251f

File tree

4 files changed

+38
-146
lines changed

4 files changed

+38
-146
lines changed

examples/typescript-graphql-request/codegen.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ const config: CodegenConfig = {
77
generates: {
88
'./src/gql/': {
99
preset: 'client',
10+
config: {
11+
documentMode: 'string',
12+
},
1013
},
1114
},
1215
hooks: { afterAllFileWrite: ['prettier --write'] },

examples/typescript-graphql-request/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"private": true,
55
"devDependencies": {
66
"@graphql-codegen/cli": "3.2.2",
7-
"@graphql-codegen/gql-tag-operations-preset": "2.1.0"
7+
"@graphql-codegen/gql-tag-operations-preset": "2.1.0",
8+
"babel-jest": "28.1.3",
9+
"jest": "28.1.3"
810
},
911
"dependencies": {
1012
"graphql": "16.6.0",
@@ -15,7 +17,7 @@
1517
"codegen": "graphql-codegen --config codegen.ts",
1618
"build": "tsc",
1719
"dev": "ts-node src/main.ts",
18-
"test:end2end": "node dist/main.js"
20+
"test:end2end": "exit 0"
1921
},
2022
"type": "commonjs",
2123
"bob": false
Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* eslint-disable */
22
import * as types from './graphql';
3-
import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
43

54
/**
65
* Map of all GraphQL operations in the project.
@@ -19,40 +18,19 @@ const documents = {
1918
types.AllPeopleWithVariablesQueryDocument,
2019
};
2120

22-
/**
23-
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
24-
*
25-
*
26-
* @example
27-
* ```ts
28-
* const query = graphql(`query GetUser($id: ID!) { user(id: $id) { name } }`);
29-
* ```
30-
*
31-
* The query argument is unknown!
32-
* Please regenerate the types.
33-
*/
34-
export function graphql(source: string): unknown;
35-
3621
/**
3722
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
3823
*/
3924
export function graphql(
4025
source: '\n query AllPeopleQuery {\n allPeople(first: 5) {\n edges {\n node {\n name\n homeworld {\n name\n }\n }\n }\n }\n }\n'
41-
): (typeof documents)['\n query AllPeopleQuery {\n allPeople(first: 5) {\n edges {\n node {\n name\n homeworld {\n name\n }\n }\n }\n }\n }\n'];
26+
): typeof import('./graphql').AllPeopleQueryDocument;
4227
/**
4328
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
4429
*/
4530
export function graphql(
4631
source: '\n query AllPeopleWithVariablesQuery($first: Int!) {\n allPeople(first: $first) {\n edges {\n node {\n name\n homeworld {\n name\n }\n }\n }\n }\n }\n'
47-
): (typeof documents)['\n query AllPeopleWithVariablesQuery($first: Int!) {\n allPeople(first: $first) {\n edges {\n node {\n name\n homeworld {\n name\n }\n }\n }\n }\n }\n'];
32+
): typeof import('./graphql').AllPeopleWithVariablesQueryDocument;
4833

4934
export function graphql(source: string) {
5035
return (documents as any)[source] ?? {};
5136
}
52-
53-
export type DocumentType<TDocumentNode extends DocumentNode<any, any>> = TDocumentNode extends DocumentNode<
54-
infer TType,
55-
any
56-
>
57-
? TType
58-
: never;

examples/typescript-graphql-request/src/gql/graphql.ts

Lines changed: 29 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable */
2-
import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
2+
import { TypedDocumentString } from '@graphql-typed-document-node/core';
33
export type Maybe<T> = T | null;
44
export type InputMaybe<T> = Maybe<T>;
55
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
@@ -1309,122 +1309,31 @@ export type AllPeopleWithVariablesQueryQuery = {
13091309
} | null;
13101310
};
13111311

1312-
export const AllPeopleQueryDocument = {
1313-
kind: 'Document',
1314-
definitions: [
1315-
{
1316-
kind: 'OperationDefinition',
1317-
operation: 'query',
1318-
name: { kind: 'Name', value: 'AllPeopleQuery' },
1319-
selectionSet: {
1320-
kind: 'SelectionSet',
1321-
selections: [
1322-
{
1323-
kind: 'Field',
1324-
name: { kind: 'Name', value: 'allPeople' },
1325-
arguments: [
1326-
{ kind: 'Argument', name: { kind: 'Name', value: 'first' }, value: { kind: 'IntValue', value: '5' } },
1327-
],
1328-
selectionSet: {
1329-
kind: 'SelectionSet',
1330-
selections: [
1331-
{
1332-
kind: 'Field',
1333-
name: { kind: 'Name', value: 'edges' },
1334-
selectionSet: {
1335-
kind: 'SelectionSet',
1336-
selections: [
1337-
{
1338-
kind: 'Field',
1339-
name: { kind: 'Name', value: 'node' },
1340-
selectionSet: {
1341-
kind: 'SelectionSet',
1342-
selections: [
1343-
{ kind: 'Field', name: { kind: 'Name', value: 'name' } },
1344-
{
1345-
kind: 'Field',
1346-
name: { kind: 'Name', value: 'homeworld' },
1347-
selectionSet: {
1348-
kind: 'SelectionSet',
1349-
selections: [{ kind: 'Field', name: { kind: 'Name', value: 'name' } }],
1350-
},
1351-
},
1352-
],
1353-
},
1354-
},
1355-
],
1356-
},
1357-
},
1358-
],
1359-
},
1360-
},
1361-
],
1362-
},
1363-
},
1364-
],
1365-
} as unknown as DocumentNode<AllPeopleQueryQuery, AllPeopleQueryQueryVariables>;
1366-
export const AllPeopleWithVariablesQueryDocument = {
1367-
kind: 'Document',
1368-
definitions: [
1369-
{
1370-
kind: 'OperationDefinition',
1371-
operation: 'query',
1372-
name: { kind: 'Name', value: 'AllPeopleWithVariablesQuery' },
1373-
variableDefinitions: [
1374-
{
1375-
kind: 'VariableDefinition',
1376-
variable: { kind: 'Variable', name: { kind: 'Name', value: 'first' } },
1377-
type: { kind: 'NonNullType', type: { kind: 'NamedType', name: { kind: 'Name', value: 'Int' } } },
1378-
},
1379-
],
1380-
selectionSet: {
1381-
kind: 'SelectionSet',
1382-
selections: [
1383-
{
1384-
kind: 'Field',
1385-
name: { kind: 'Name', value: 'allPeople' },
1386-
arguments: [
1387-
{
1388-
kind: 'Argument',
1389-
name: { kind: 'Name', value: 'first' },
1390-
value: { kind: 'Variable', name: { kind: 'Name', value: 'first' } },
1391-
},
1392-
],
1393-
selectionSet: {
1394-
kind: 'SelectionSet',
1395-
selections: [
1396-
{
1397-
kind: 'Field',
1398-
name: { kind: 'Name', value: 'edges' },
1399-
selectionSet: {
1400-
kind: 'SelectionSet',
1401-
selections: [
1402-
{
1403-
kind: 'Field',
1404-
name: { kind: 'Name', value: 'node' },
1405-
selectionSet: {
1406-
kind: 'SelectionSet',
1407-
selections: [
1408-
{ kind: 'Field', name: { kind: 'Name', value: 'name' } },
1409-
{
1410-
kind: 'Field',
1411-
name: { kind: 'Name', value: 'homeworld' },
1412-
selectionSet: {
1413-
kind: 'SelectionSet',
1414-
selections: [{ kind: 'Field', name: { kind: 'Name', value: 'name' } }],
1415-
},
1416-
},
1417-
],
1418-
},
1419-
},
1420-
],
1421-
},
1422-
},
1423-
],
1424-
},
1425-
},
1426-
],
1427-
},
1428-
},
1429-
],
1430-
} as unknown as DocumentNode<AllPeopleWithVariablesQueryQuery, AllPeopleWithVariablesQueryQueryVariables>;
1312+
export const AllPeopleQueryDocument = `
1313+
query AllPeopleQuery {
1314+
allPeople(first: 5) {
1315+
edges {
1316+
node {
1317+
name
1318+
homeworld {
1319+
name
1320+
}
1321+
}
1322+
}
1323+
}
1324+
}
1325+
` as unknown as TypedDocumentString<AllPeopleQueryQuery, AllPeopleQueryQueryVariables>;
1326+
export const AllPeopleWithVariablesQueryDocument = `
1327+
query AllPeopleWithVariablesQuery($first: Int!) {
1328+
allPeople(first: $first) {
1329+
edges {
1330+
node {
1331+
name
1332+
homeworld {
1333+
name
1334+
}
1335+
}
1336+
}
1337+
}
1338+
}
1339+
` as unknown as TypedDocumentString<AllPeopleWithVariablesQueryQuery, AllPeopleWithVariablesQueryQueryVariables>;

0 commit comments

Comments
 (0)