Skip to content

Commit

Permalink
chore(docs): make gql examples more idiomatic
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt committed Oct 14, 2024
1 parent c14b3d0 commit 44cab1e
Show file tree
Hide file tree
Showing 21 changed files with 149 additions and 165 deletions.
8 changes: 3 additions & 5 deletions examples/30_gql/gql_gql-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ const graffle = Graffle.create({
schema: publicGraphQLSchemaEndpoints.Pokemon,
})

const document = /* gql */ `
const data = await graffle.gql`
{
pokemon {
name
}
}
`

const data = await graffle.gql(document).send()
}
`.send()

show(data)
10 changes: 4 additions & 6 deletions examples/30_gql/gql_gql-string_gql-typed__gql-string-typed.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* This example shows how to send a request using a string for the GraphQL document while also being typesafe in regards to the passed variables and return type.
* Note that the typing is a cast and would not catch if the actual GraphQL document disagreed with the types. As the comment suggests below, ideally some sort
* of automation would generate the types for you.
* Note that the typing of a string is effectively a cast here and so would not catch if the actual GraphQL document disagreed with your types. As the comment
* suggests below, ideally some sort of automation would generate the types for you.
*/

import { Graffle, type TypedDocument } from '../../src/entrypoints/main.js'
Expand Down Expand Up @@ -33,7 +33,7 @@ type Document = TypedDocument.String<
{ name: string }
>

const document: Document = /* gql */ `
const data = await graffle.gql<Document>`
query pokemonByName ($name: String!) {
pokemonByName (name: $name) {
name
Expand All @@ -45,8 +45,6 @@ const document: Document = /* gql */ `
}
}
}
`

const data = await graffle.gql(document).send({ name: `Pikachu` })
`.send({ name: `Pikachu` })

show(data?.pokemonByName)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
headers: Headers {
accept: 'application/graphql-response+json; charset=utf-8, application/json; charset=utf-8',
'content-type': 'application/json',
'x-sent-at-time': '1728856241218'
'x-sent-at-time': '1728912147789'
},
signal: undefined,
method: 'post',
Expand Down
2 changes: 1 addition & 1 deletion examples/__outputs__/20_output/output_envelope.output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
headers: Headers {
'content-type': 'application/graphql-response+json; charset=utf-8',
'content-length': '142',
date: 'Sun, 13 Oct 2024 21:50:41 GMT',
date: 'Mon, 14 Oct 2024 13:22:28 GMT',
connection: 'keep-alive',
'keep-alive': 'timeout=5'
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
}
},
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
traceId: '0d775d0099c7910506a0772440555fbe',
parentId: '9b0787a81673ace4',
traceId: '27049eba5a2aefdef485bb13b3c9103a',
parentId: 'e85b98029274120c',
traceState: undefined,
name: 'encode',
id: 'e6fbdb4081ec6e4e',
id: 'c50625041c2a6ed5',
kind: 0,
timestamp: 1728856242273000,
duration: 1418.125,
timestamp: 1728912148775000,
duration: 1505.542,
attributes: {},
status: { code: 0 },
events: [],
Expand All @@ -33,14 +33,14 @@
}
},
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
traceId: '0d775d0099c7910506a0772440555fbe',
parentId: '9b0787a81673ace4',
traceId: '27049eba5a2aefdef485bb13b3c9103a',
parentId: 'e85b98029274120c',
traceState: undefined,
name: 'pack',
id: 'c20c4b4a0bb60890',
id: '11f13791202ae25b',
kind: 0,
timestamp: 1728856242277000,
duration: 11234.958,
timestamp: 1728912148779000,
duration: 12466.834,
attributes: {},
status: { code: 0 },
events: [],
Expand All @@ -57,14 +57,14 @@
}
},
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
traceId: '0d775d0099c7910506a0772440555fbe',
parentId: '9b0787a81673ace4',
traceId: '27049eba5a2aefdef485bb13b3c9103a',
parentId: 'e85b98029274120c',
traceState: undefined,
name: 'exchange',
id: 'b37626f52b507127',
id: 'e6cfb7ae84ff6884',
kind: 0,
timestamp: 1728856242288000,
duration: 106411.25,
timestamp: 1728912148792000,
duration: 21899.333,
attributes: {},
status: { code: 0 },
events: [],
Expand All @@ -81,14 +81,14 @@
}
},
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
traceId: '0d775d0099c7910506a0772440555fbe',
parentId: '9b0787a81673ace4',
traceId: '27049eba5a2aefdef485bb13b3c9103a',
parentId: 'e85b98029274120c',
traceState: undefined,
name: 'unpack',
id: '7cdde5c9f15d334d',
id: 'd4efa36db6b171cd',
kind: 0,
timestamp: 1728856242395000,
duration: 1244.125,
timestamp: 1728912148814000,
duration: 1314.958,
attributes: {},
status: { code: 0 },
events: [],
Expand All @@ -105,14 +105,14 @@
}
},
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
traceId: '0d775d0099c7910506a0772440555fbe',
parentId: '9b0787a81673ace4',
traceId: '27049eba5a2aefdef485bb13b3c9103a',
parentId: 'e85b98029274120c',
traceState: undefined,
name: 'decode',
id: 'b048da7b0a82b097',
id: '58283a74b8b0c8ac',
kind: 0,
timestamp: 1728856242396000,
duration: 181.792,
timestamp: 1728912148816000,
duration: 245.125,
attributes: {},
status: { code: 0 },
events: [],
Expand All @@ -129,14 +129,14 @@
}
},
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
traceId: '0d775d0099c7910506a0772440555fbe',
traceId: '27049eba5a2aefdef485bb13b3c9103a',
parentId: undefined,
traceState: undefined,
name: 'request',
id: '9b0787a81673ace4',
id: 'e85b98029274120c',
kind: 0,
timestamp: 1728856242273000,
duration: 123962.916,
timestamp: 1728912148775000,
duration: 41363.958,
attributes: {},
status: { code: 0 },
events: [],
Expand Down
2 changes: 1 addition & 1 deletion website/content/_snippets/example-links/extension.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p class="ExampleLinks">Examples <span class="ExampleLinksTitleSeparator">-></span> <a href="../../examples/transport-http/custom-fetch">Custom Fetch</a> <span class="ExampleLinksSeparator"></span> <a href="../../examples/transport-http/dynamic-headers">Dynamic Headers</a> <span class="ExampleLinksSeparator"></span> <a href="../../examples/extension/introspection">Introspection</a> <span class="ExampleLinksSeparator"></span> <a href="../../examples/extension/opentelemetry">Opentelemetry</a> <span class="ExampleLinksSeparator"></span> <a href="../../examples/extension/throws">Throws</a></p>
<p class="ExampleLinks">Examples <span class="ExampleLinksTitleSeparator">-></span> <a href="../../examples/extension/introspection">Introspection</a> <span class="ExampleLinksSeparator"></span> <a href="../../examples/extension/opentelemetry">Opentelemetry</a> <span class="ExampleLinksSeparator"></span> <a href="../../examples/extension/throws">Throws</a> <span class="ExampleLinksSeparator"></span> <a href="../../examples/transport-http/custom-fetch">Custom Fetch</a> <span class="ExampleLinksSeparator"></span> <a href="../../examples/transport-http/dynamic-headers">Dynamic Headers</a></p>
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ console.log(data)
}
},
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
traceId: '0d775d0099c7910506a0772440555fbe',
parentId: '9b0787a81673ace4',
traceId: '27049eba5a2aefdef485bb13b3c9103a',
parentId: 'e85b98029274120c',
traceState: undefined,
name: 'encode',
id: 'e6fbdb4081ec6e4e',
id: 'c50625041c2a6ed5',
kind: 0,
timestamp: 1728856242273000,
duration: 1418.125,
timestamp: 1728912148775000,
duration: 1505.542,
attributes: {},
status: { code: 0 },
events: [],
Expand All @@ -64,14 +64,14 @@ console.log(data)
}
},
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
traceId: '0d775d0099c7910506a0772440555fbe',
parentId: '9b0787a81673ace4',
traceId: '27049eba5a2aefdef485bb13b3c9103a',
parentId: 'e85b98029274120c',
traceState: undefined,
name: 'pack',
id: 'c20c4b4a0bb60890',
id: '11f13791202ae25b',
kind: 0,
timestamp: 1728856242277000,
duration: 11234.958,
timestamp: 1728912148779000,
duration: 12466.834,
attributes: {},
status: { code: 0 },
events: [],
Expand All @@ -91,14 +91,14 @@ console.log(data)
}
},
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
traceId: '0d775d0099c7910506a0772440555fbe',
parentId: '9b0787a81673ace4',
traceId: '27049eba5a2aefdef485bb13b3c9103a',
parentId: 'e85b98029274120c',
traceState: undefined,
name: 'exchange',
id: 'b37626f52b507127',
id: 'e6cfb7ae84ff6884',
kind: 0,
timestamp: 1728856242288000,
duration: 106411.25,
timestamp: 1728912148792000,
duration: 21899.333,
attributes: {},
status: { code: 0 },
events: [],
Expand All @@ -118,14 +118,14 @@ console.log(data)
}
},
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
traceId: '0d775d0099c7910506a0772440555fbe',
parentId: '9b0787a81673ace4',
traceId: '27049eba5a2aefdef485bb13b3c9103a',
parentId: 'e85b98029274120c',
traceState: undefined,
name: 'unpack',
id: '7cdde5c9f15d334d',
id: 'd4efa36db6b171cd',
kind: 0,
timestamp: 1728856242395000,
duration: 1244.125,
timestamp: 1728912148814000,
duration: 1314.958,
attributes: {},
status: { code: 0 },
events: [],
Expand All @@ -145,14 +145,14 @@ console.log(data)
}
},
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
traceId: '0d775d0099c7910506a0772440555fbe',
parentId: '9b0787a81673ace4',
traceId: '27049eba5a2aefdef485bb13b3c9103a',
parentId: 'e85b98029274120c',
traceState: undefined,
name: 'decode',
id: 'b048da7b0a82b097',
id: '58283a74b8b0c8ac',
kind: 0,
timestamp: 1728856242396000,
duration: 181.792,
timestamp: 1728912148816000,
duration: 245.125,
attributes: {},
status: { code: 0 },
events: [],
Expand All @@ -172,14 +172,14 @@ console.log(data)
}
},
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
traceId: '0d775d0099c7910506a0772440555fbe',
traceId: '27049eba5a2aefdef485bb13b3c9103a',
parentId: undefined,
traceState: undefined,
name: 'request',
id: '9b0787a81673ace4',
id: 'e85b98029274120c',
kind: 0,
timestamp: 1728856242273000,
duration: 123962.916,
timestamp: 1728912148775000,
duration: 41363.958,
attributes: {},
status: { code: 0 },
events: [],
Expand Down
Loading

0 comments on commit 44cab1e

Please sign in to comment.