-
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
9a4be38
commit ba48bf9
Showing
43 changed files
with
773 additions
and
320 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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const publicGraphQLSchemaEndpoints = { | ||
SocialStudies: `https://countries.trevorblades.com/graphql`, | ||
} |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* eslint-disable */ | ||
import { SocialStudies } from './$generated-clients/SocialStudies/__.js' | ||
|
||
const socialStudies = SocialStudies.create() | ||
|
||
const countries = await socialStudies.query.countries({ | ||
$: { filter: { name: { in: ['Canada', 'Germany', 'Japan'] } } }, | ||
name: true, | ||
continent: { name: true }, | ||
}) | ||
|
||
console.log(countries) |
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
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import type { TypedQueryDocumentNode } from 'graphql' | ||
import { gql, Graffle } from '../src/entrypoints/alpha/main.js' | ||
import { publicGraphQLSchemaEndpoints } from './$helpers.js' | ||
|
||
const graffle = Graffle.create({ | ||
schema: publicGraphQLSchemaEndpoints.SocialStudies, | ||
}) | ||
|
||
/*************************************** Variation 1 *************************************** | ||
* - | ||
* - | ||
* - | ||
* You can pass type variables to the `gql` template tag. | ||
* - | ||
*/ | ||
|
||
{ | ||
const document = gql<{ countries: { name: string; continent: { name: string } }[] }, { filter: string[] }>` | ||
query countries ($filter: [String!]) { | ||
countries (filter: { name: { in: $filter } }) { | ||
name | ||
continent { | ||
name | ||
} | ||
} | ||
} | ||
` | ||
|
||
const result = await graffle.raw({ document, variables: { filter: [`Canada`, `Germany`, `Japan`] } }) | ||
|
||
console.log(result.data?.countries) | ||
} | ||
|
||
/*************************************** Variation 2 *************************************** | ||
* - | ||
* - | ||
* - | ||
* You can also cast the type if you have a reference to a pre constructed type. | ||
* - | ||
*/ | ||
|
||
{ | ||
type Document = TypedQueryDocumentNode< | ||
{ countries: { name: string; continent: { name: string } }[] }, | ||
{ filter: string[] } | ||
> | ||
|
||
const document: Document = gql` | ||
query countries ($filter: [String!]) { | ||
countries (filter: { name: { in: $filter } }) { | ||
name | ||
continent { | ||
name | ||
} | ||
} | ||
} | ||
` | ||
|
||
const result = await graffle.raw({ document, variables: { filter: [`Canada`, `Germany`, `Japan`] } }) | ||
|
||
console.log(result.data?.countries) | ||
} |
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,21 +1,22 @@ | ||
import { gql, Graffle } from '../src/entrypoints/alpha/main.js' | ||
import { publicGraphQLSchemaEndpoints } from './$helpers.js' | ||
|
||
const graffle = Graffle.create({ schema: `https://countries.trevorblades.com/graphql` }) | ||
const graffle = Graffle.create({ | ||
schema: publicGraphQLSchemaEndpoints.SocialStudies, | ||
}) | ||
|
||
// todo typed document node | ||
// interface Data { | ||
// countries: { name }[] | ||
// } | ||
// const { data } = await request<Data>( | ||
const result = await graffle.raw({ | ||
document: gql` | ||
query countries ($filter: [String!]) { | ||
countries (filter: { name: { in: $filter } }) { | ||
name | ||
continent { | ||
name | ||
} | ||
} | ||
} | ||
`, | ||
variables: { filter: [`Canada`, `Germany`, `Japan`] }, | ||
}) | ||
|
||
const { data } = await graffle.rawOrThrow( | ||
gql` | ||
{ | ||
countries { | ||
name | ||
} | ||
} | ||
`, | ||
) | ||
|
||
console.log(data) | ||
console.log(result.data) |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Graffle } from '../src/entrypoints/alpha/main.js' | ||
// todo from '../src/entrypoints/alpha/utils.js' | ||
import type { TypedDocumentString } from '../src/layers/0_functions/types.js' | ||
import { publicGraphQLSchemaEndpoints } from './$helpers.js' | ||
|
||
const graffle = Graffle.create({ | ||
schema: publicGraphQLSchemaEndpoints.SocialStudies, | ||
}) | ||
|
||
/** | ||
* @remarks Typically this type would come from your code generation tool. | ||
* | ||
* @see https://the-guild.dev/graphql/codegen/plugins/presets/preset-client#documentmode | ||
* @see https://github.com/jasonkuhrt/graphql-request/issues/997 | ||
*/ | ||
type Document = TypedDocumentString< | ||
{ countries: { name: string; continent: { name: string } }[] }, | ||
{ filter: string[] } | ||
> | ||
|
||
const document: Document = /* gql */ ` | ||
query countries ($filter: [String!]) { | ||
countries (filter: { name: { in: $filter } }) { | ||
name | ||
continent { | ||
name | ||
} | ||
} | ||
} | ||
` | ||
|
||
const result = await graffle.rawString({ | ||
document, | ||
variables: { filter: [`Canada`, `Germany`, `Japan`] }, | ||
}) | ||
|
||
console.log(result.data?.countries) |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Graffle } from '../src/entrypoints/alpha/main.js' | ||
import { publicGraphQLSchemaEndpoints } from './$helpers.js' | ||
|
||
const graffle = Graffle.create({ | ||
schema: publicGraphQLSchemaEndpoints.SocialStudies, | ||
}) | ||
|
||
const document = /* gql */ ` | ||
{ | ||
countries { | ||
name | ||
} | ||
} | ||
` | ||
|
||
const result = await graffle.rawString({ | ||
document, | ||
}) | ||
|
||
console.log(result.data) |
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
Oops, something went wrong.