Skip to content

Commit

Permalink
Revert graphql-request to actually test graphql-request
Browse files Browse the repository at this point in the history
  • Loading branch information
eddeee888 committed Jan 17, 2025
1 parent f24f399 commit 6dae7a6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
3 changes: 2 additions & 1 deletion examples/typescript-graphql-request/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
},
"dependencies": {
"graphql": "16.9.0",
"graphql-yoga": "5.7.0"
"graphql-yoga": "5.7.0",
"graphql-request": "5.2.0"
},
"scripts": {
"codegen": "graphql-codegen --config codegen.ts",
Expand Down
22 changes: 10 additions & 12 deletions examples/typescript-graphql-request/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { GraphQLClient } from 'graphql-request';
import { graphql } from './gql';
import { AllPeopleQueryQuery } from './gql/graphql';

Expand Down Expand Up @@ -33,17 +34,14 @@ const AllPeopleWithVariablesQueryDocument = graphql(/* GraphQL */ `

const apiUrl = 'https://graphql.org/graphql/';

export const getPeople = async (first?: number) => {
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 client = new GraphQLClient(apiUrl);

const res: AllPeopleQueryQuery = (await response.json()).data;
return res.allPeople?.edges;
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;
};

0 comments on commit 6dae7a6

Please sign in to comment.