-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a446365
commit e596527
Showing
12 changed files
with
245 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,27 @@ | ||
import { GraphQLClient } from '../src/index.js' | ||
;(async () => { | ||
const endpoint = `https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr` | ||
import { gql, GraphQLClient } from '../src/index.js' | ||
|
||
const graphQLClient = new GraphQLClient(endpoint, { | ||
headers: { | ||
authorization: `Bearer MY_TOKEN`, | ||
}, | ||
}) | ||
const endpoint = `https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr` | ||
|
||
const query = /* GraphQL */ ` | ||
{ | ||
Movie(title: "Inception") { | ||
releaseDate | ||
actors { | ||
name | ||
} | ||
const graphQLClient = new GraphQLClient(endpoint, { | ||
headers: { | ||
authorization: `Bearer MY_TOKEN`, | ||
}, | ||
}) | ||
|
||
const query = gql` | ||
{ | ||
Movie(title: "Inception") { | ||
releaseDate | ||
actors { | ||
name | ||
} | ||
} | ||
` | ||
|
||
interface TData { | ||
Movie: { releaseDate: string; actors: Array<{ name: string }> } | ||
} | ||
` | ||
|
||
interface TData { | ||
Movie: { releaseDate: string; actors: Array<{ name: string }> } | ||
} | ||
|
||
const data = await graphQLClient.request<TData>(query) | ||
console.log(JSON.stringify(data, undefined, 2)) | ||
})().catch((error) => console.error(error)) | ||
const data = await graphQLClient.request<TData>(query) | ||
console.log(JSON.stringify(data, undefined, 2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,56 @@ | ||
import { batchRequests } from '../src/index.js' | ||
;(async function () { | ||
const endpoint = `https://api.spacex.land/graphql/` | ||
|
||
const query1 = /* GraphQL */ ` | ||
query ($id: ID!) { | ||
capsule(id: $id) { | ||
id | ||
landings | ||
} | ||
} | ||
` | ||
const variables1 = { | ||
id: `C105`, | ||
} | ||
import { batchRequests, gql } from '../src/index.js' | ||
|
||
interface TData1 { | ||
data: { capsule: { id: string; landings: number } } | ||
} | ||
const endpoint = `https://api.spacex.land/graphql/` | ||
|
||
const query2 = /* GraphQL */ ` | ||
{ | ||
rockets(limit: 10) { | ||
active | ||
} | ||
const query1 = gql` | ||
query ($id: ID!) { | ||
capsule(id: $id) { | ||
id | ||
landings | ||
} | ||
` | ||
|
||
interface TData2 { | ||
data: { rockets: { active: boolean }[] } | ||
} | ||
|
||
const query3 = /* GraphQL */ ` | ||
query ($id: ID!) { | ||
core(id: $id) { | ||
id | ||
block | ||
original_launch | ||
} | ||
` | ||
const variables1 = { | ||
id: `C105`, | ||
} | ||
|
||
interface TData1 { | ||
data: { capsule: { id: string; landings: number } } | ||
} | ||
|
||
const query2 = gql` | ||
{ | ||
rockets(limit: 10) { | ||
active | ||
} | ||
` | ||
|
||
const variables3 = { | ||
id: `B1015`, | ||
} | ||
|
||
interface TData3 { | ||
data: { core: { id: string; block: number; original_launch: string } } | ||
` | ||
|
||
interface TData2 { | ||
data: { rockets: { active: boolean }[] } | ||
} | ||
|
||
const query3 = gql` | ||
query ($id: ID!) { | ||
core(id: $id) { | ||
id | ||
block | ||
original_launch | ||
} | ||
} | ||
|
||
const data = await batchRequests<[TData1, TData2, TData3]>(endpoint, [ | ||
{ document: query1, variables: variables1 }, | ||
{ document: query2 }, | ||
{ document: query3, variables: variables3 }, | ||
]) | ||
console.log(JSON.stringify(data, undefined, 2)) | ||
})().catch((error) => console.error(error)) | ||
` | ||
|
||
const variables3 = { | ||
id: `B1015`, | ||
} | ||
|
||
interface TData3 { | ||
data: { core: { id: string; block: number; original_launch: string } } | ||
} | ||
|
||
const data = await batchRequests<[TData1, TData2, TData3]>(endpoint, [ | ||
{ document: query1, variables: variables1 }, | ||
{ document: query2 }, | ||
{ document: query3, variables: variables3 }, | ||
]) | ||
console.log(JSON.stringify(data, undefined, 2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,29 @@ | ||
;(global as any).fetch = require(`fetch-cookie/node-fetch`)(require(`node-fetch`)) | ||
|
||
import { GraphQLClient } from '../src/index.js' | ||
;(async function () { | ||
const endpoint = `https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr` | ||
import { gql, GraphQLClient } from '../src/index.js' | ||
|
||
const graphQLClient = new GraphQLClient(endpoint, { | ||
headers: { | ||
authorization: `Bearer MY_TOKEN`, | ||
}, | ||
}) | ||
const endpoint = `https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr` | ||
|
||
const query = /* GraphQL */ ` | ||
{ | ||
Movie(title: "Inception") { | ||
releaseDate | ||
actors { | ||
name | ||
} | ||
const graphQLClient = new GraphQLClient(endpoint, { | ||
headers: { | ||
authorization: `Bearer MY_TOKEN`, | ||
}, | ||
}) | ||
|
||
const query = gql` | ||
{ | ||
Movie(title: "Inception") { | ||
releaseDate | ||
actors { | ||
name | ||
} | ||
} | ||
` | ||
|
||
interface TData { | ||
Movie: { releaseDate: string; actors: Array<{ name: string }> } | ||
} | ||
` | ||
|
||
interface TData { | ||
Movie: { releaseDate: string; actors: Array<{ name: string }> } | ||
} | ||
|
||
const data = await graphQLClient.rawRequest<TData>(query) | ||
console.log(JSON.stringify(data, undefined, 2)) | ||
})().catch((error) => console.error(error)) | ||
const data = await graphQLClient.rawRequest<TData>(query) | ||
console.log(JSON.stringify(data, undefined, 2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,24 @@ | ||
import { GraphQLClient } from '../src/index.js' | ||
import { gql, GraphQLClient } from '../src/index.js' | ||
import fetch from 'cross-fetch' | ||
;(async function () { | ||
const endpoint = `https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr` | ||
|
||
const graphQLClient = new GraphQLClient(endpoint, { fetch: fetch }) | ||
const endpoint = `https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr` | ||
|
||
const query = /* GraphQL */ ` | ||
{ | ||
Movie(title: "Inception") { | ||
releaseDate | ||
actors { | ||
name | ||
} | ||
const graphQLClient = new GraphQLClient(endpoint, { fetch: fetch }) | ||
|
||
const query = gql` | ||
{ | ||
Movie(title: "Inception") { | ||
releaseDate | ||
actors { | ||
name | ||
} | ||
} | ||
` | ||
|
||
interface TData { | ||
Movie: { releaseDate: string; actors: Array<{ name: string }> } | ||
} | ||
` | ||
|
||
interface TData { | ||
Movie: { releaseDate: string; actors: Array<{ name: string }> } | ||
} | ||
|
||
const data = await graphQLClient.rawRequest<TData>(query) | ||
console.log(JSON.stringify(data, undefined, 2)) | ||
})().catch((error) => console.error(error)) | ||
const data = await graphQLClient.rawRequest<TData>(query) | ||
console.log(JSON.stringify(data, undefined, 2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,26 @@ | ||
import { request } from '../src/index.js' | ||
;(async function () { | ||
const endpoint = `https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr` | ||
import { gql, request } from '../src/index.js' | ||
|
||
const query = /* GraphQL */ ` | ||
{ | ||
Movie(title: "Inception") { | ||
releaseDate | ||
actors { | ||
fullname # "Cannot query field 'fullname' on type 'Actor'. Did you mean 'name'?" | ||
} | ||
const endpoint = `https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr` | ||
|
||
const query = gql` | ||
{ | ||
Movie(title: "Inception") { | ||
releaseDate | ||
actors { | ||
fullname # "Cannot query field 'fullname' on type 'Actor'. Did you mean 'name'?" | ||
} | ||
} | ||
` | ||
|
||
interface TData { | ||
Movie: { releaseDate: string; actors: Array<{ name: string }> } | ||
} | ||
` | ||
|
||
try { | ||
const data = await request<TData>(endpoint, query) | ||
console.log(JSON.stringify(data, undefined, 2)) | ||
} catch (error) { | ||
console.error(JSON.stringify(error, undefined, 2)) | ||
process.exit(1) | ||
} | ||
})().catch((error) => console.error(error)) | ||
interface TData { | ||
Movie: { releaseDate: string; actors: Array<{ name: string }> } | ||
} | ||
|
||
try { | ||
const data = await request<TData>(endpoint, query) | ||
console.log(JSON.stringify(data, undefined, 2)) | ||
} catch (error) { | ||
console.error(JSON.stringify(error, undefined, 2)) | ||
process.exit(1) | ||
} |
Oops, something went wrong.