Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
tjjfv committed Feb 2, 2022
1 parent a9a795a commit 8726a2a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
4 changes: 3 additions & 1 deletion playground/example/schema.gql.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# #####
# Example GraphQL Schema
# #####

# This file is an example of a user-created schema.

# You can edit this schema file.
# * You can edit this GraphQL schema file. *

schema {
query: Query
Expand Down
30 changes: 20 additions & 10 deletions playground/example/usage.ts.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
// @ts-nocheck
// -----

// Example Typescript Usage File
// #####
// Example Typescript Usage
// #####

// Below are examples of a user-created Typescript code that uses the type information generated by gqx
// This file is an example of code that uses the gqx generated types and objects.

// You can edit this TypeScript file.
// * You can edit this TypeScript file. *

import { gqx, Book, Person, Author, User } from "./gqx";

// #####
// Example of fully typed fragments, queries, and results
// ###
// Example of fully-typed fragment, query, input, and result
// ###

const bookFrag = Book.$(
Book.id,
Expand All @@ -19,23 +22,25 @@ const bookFrag = Book.$(
Book.author.books.title,
);

// Hover over the result to see the type
// * hover over the result to see the type
const bookResult = await gqx.query.getBook({ id: "abc" }, bookFrag)

bookResult.title // string
bookResult.author.name // string
bookResult.author.books // Array<{ __typename: string, title: string }>

// #####

// ###
// Example of handling fragments with interfaces and unions
// ###

const peopleQueryFrag = Person.$(
Person.name,
Author.books.id, // Author implements Person
User.username, // User implements Person
)

// Hover over the result to see the union type
// * hover over the result to see the union type
const peopleResult = await gqx.query.getPeople({ filter: "A" }, peopleQueryFrag)

for(const person of peopleResult) {
Expand All @@ -49,8 +54,11 @@ for(const person of peopleResult) {
}
}

// #####
// The following frament definitions result in equaivalent fragments
// ###
// Example the flexible fully-typed formats for defining and composing fragments
// ###

// The following fragment definitions result in equaivalent fragments

const bookFragment1 = Book.$(
Book.id,
Expand Down Expand Up @@ -83,6 +91,8 @@ const bookFragment3 = Book.$(
);

// The equivalent fragments result in equivalent result types

// * hover each result to see that each has the same type
const result1 = await gqx.query.getBook({ id: "abc" }, bookFragment1)
const result2 = await gqx.query.getBook({ id: "abc" }, bookFragment2)
const result3 = await gqx.query.getBook({ id: "abc" }, bookFragment3)

0 comments on commit 8726a2a

Please sign in to comment.