Skip to content

Commit

Permalink
Avoid using graphql-request in examples because it does not work
Browse files Browse the repository at this point in the history
  • Loading branch information
eddeee888 committed Jan 17, 2025
1 parent e8d00e6 commit c489b4a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
3 changes: 1 addition & 2 deletions examples/typescript-graphql-request/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
23 changes: 12 additions & 11 deletions examples/typescript-graphql-request/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable no-console */
import { GraphQLClient } from 'graphql-request';
import { graphql } from './gql';
import { AllPeopleQueryQuery } from './gql/graphql';

Expand Down Expand Up @@ -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;
};

0 comments on commit c489b4a

Please sign in to comment.