diff --git a/examples/typescript-graphql-request/package.json b/examples/typescript-graphql-request/package.json index edecc849cb8..f8e1f9519fa 100644 --- a/examples/typescript-graphql-request/package.json +++ b/examples/typescript-graphql-request/package.json @@ -9,8 +9,7 @@ }, "dependencies": { "graphql": "16.9.0", - "graphql-yoga": "5.7.0", - "graphql-request": "5.2.0" + "graphql-yoga": "5.7.0" }, "scripts": { "codegen": "graphql-codegen --config codegen.ts", diff --git a/examples/typescript-graphql-request/src/main.ts b/examples/typescript-graphql-request/src/main.ts index 55fed87f1a1..f81d8907d65 100644 --- a/examples/typescript-graphql-request/src/main.ts +++ b/examples/typescript-graphql-request/src/main.ts @@ -1,5 +1,3 @@ -/* eslint-disable no-console */ -import { GraphQLClient } from 'graphql-request'; import { graphql } from './gql'; import { AllPeopleQueryQuery } from './gql/graphql'; @@ -35,14 +33,17 @@ const AllPeopleWithVariablesQueryDocument = graphql(/* GraphQL */ ` const apiUrl = 'https://graphql.org/graphql/'; -const client = new GraphQLClient(apiUrl); - export const getPeople = async (first?: number) => { - let res: AllPeopleQueryQuery; - if (first) { - res = await client.request(AllPeopleWithVariablesQueryDocument.toString(), { first }); - } else { - res = await client.request(AllPeopleQueryDocument.toString()); - } - return res?.allPeople?.edges; + const request = first + ? { query: AllPeopleWithVariablesQueryDocument.toString(), variables: { first } } + : { query: AllPeopleQueryDocument.toString() }; + + const response = await fetch(apiUrl, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(request), + }); + + const res: AllPeopleQueryQuery = (await response.json()).data; + return res.allPeople?.edges; };