-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extracted playground example file text
- Loading branch information
Showing
5 changed files
with
183 additions
and
179 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
|
||
# gql schema file | ||
|
||
schema { | ||
query: Query | ||
} | ||
|
||
type Query { | ||
getPerson(id: ID!): Person! | ||
getAuthor(id: ID!): Author! | ||
getBook(id: ID!): Book! | ||
listBooks(cursor: Cursor, filter: BookFilter): [Book!]! | ||
} | ||
|
||
input Cursor { | ||
start: Int! | ||
limit: Int! | ||
} | ||
|
||
type Book { | ||
id: ID! | ||
language: Language! | ||
author: Author! | ||
title: String! | ||
description: String! | ||
categories: [Category!]! | ||
translation(language: Language!): Book | ||
} | ||
|
||
input BookFilter { | ||
title: String | ||
author: AuthorFilter | ||
categories: [Category!] | ||
} | ||
|
||
type Author implements Person { | ||
id: ID! | ||
name: String! | ||
books: [Book!]! | ||
favoriteBook: Book! | ||
} | ||
|
||
type User implements Person { | ||
id: ID! | ||
name: String | ||
favoriteBook: Book | ||
} | ||
|
||
interface Person { | ||
id: ID! | ||
name: String | ||
favoriteBook: Book | ||
} | ||
|
||
input AuthorFilter { | ||
name: String | ||
} | ||
|
||
enum Category { | ||
Horror | ||
SciFi | ||
Fiction | ||
Fantasy | ||
NonFiction | ||
Romance | ||
Historical | ||
Mystery | ||
Childrens | ||
Dystopian | ||
Utopian | ||
Religous | ||
} | ||
|
||
|
||
enum Language { | ||
ab ae af ak am an ar as av ay az ba be bg bh bi bm bn bo br bs ca ce ch co cr cs cu cv cy | ||
da de dv dz ee el en eo es et eu fa ff fi fj fo fr fy ga gd gl gn gu gv ha he hi ho hr ht | ||
hu hy hz ia id ie ig ii ik io is it iu ja jv ka kg ki kj kk kl km kn ko kr ks ku kv kw ky | ||
la lb lg li ln lo lt lu lv mg mh mi mk ml mn mr ms mt my na nb nd ne ng nl nn no nr nv ny | ||
oc oj om or os pa pi pl ps pt qu rm rn ro ru rw sa sc sd se sg si sk sl sm sn so sq sr ss | ||
st su sv sw ta te tg th ti tk tl tn to tr ts tt tw ty ug uk ur uz ve vi vo wa wo xh yi yo | ||
za zh zu | ||
} |
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,68 @@ | ||
// ts file | ||
|
||
import { gqx, Author, Book, Person } from "./gqx"; | ||
|
||
const authorFrag = Author.$( | ||
Author.id, | ||
Author.name, | ||
); | ||
|
||
const bookFrag1 = Book.$( | ||
Book.id, | ||
Book.title, | ||
Book.author.name, | ||
); | ||
|
||
const bookFrag2 = Book.$( | ||
Book.id, | ||
Book.author.$(authorFrag) | ||
); | ||
|
||
const bookFragCombined = Book.$( | ||
bookFrag1, | ||
bookFrag2, | ||
); | ||
|
||
gqx.query.getBook({ id: "abc" }, bookFragCombined).then(book => { | ||
book; // Hover | ||
/* | ||
(parameter) book: { | ||
__typename: "Book"; | ||
id: string; | ||
title: string; | ||
author: { | ||
__typename: "Author"; | ||
id: string; | ||
name: string; | ||
}; | ||
} | ||
*/ | ||
}) | ||
|
||
const personFrag = Person.$( | ||
Person.name, | ||
// Author implements the interface Person | ||
Author.books.id, | ||
) | ||
|
||
gqx.query.getPerson({ id: "foo" }, personFrag).then(person => { | ||
person; // Hover | ||
/* | ||
(parameter) person: { | ||
__typename: "Author"; | ||
name: string; | ||
books: { | ||
__typename: "Book"; | ||
id: string; | ||
}[]; | ||
} | { | ||
__typename: "User"; | ||
name: string; | ||
} | ||
*/ | ||
// @ts-expect-error may not exist | ||
person.books | ||
if(person.__typename === "Author"){ | ||
person.books[0].id // string | ||
} | ||
}) |
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,24 @@ | ||
export * from "./output"; | ||
|
||
import { $$GqxReturn, $$AnyProp, $$Frag, $$Input, $$Output, $$generateObject } from "./output"; | ||
|
||
// Type of e.g. gqx.query.getBook | ||
type GqxOut_<I extends $$AnyProp> = | ||
<T extends $$Frag<I>>(input: $$Input<I>, frag: T) | ||
=> Promise<$$Output<I, T>> | ||
|
||
// HKT encoding to pass to $$generateObject | ||
interface GqxOut extends $$GqxReturn { | ||
return: GqxOut_<this["input"]>; | ||
} | ||
|
||
// Imported by codegen output | ||
export interface $$Scalars { | ||
String: string; | ||
Boolean: boolean; | ||
Float: number; | ||
Int: number; | ||
ID: string; | ||
} | ||
|
||
export const gqx = $$generateObject<GqxOut>(() => null!) |
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,4 @@ | ||
declare module "*.txt" { | ||
const content: string; | ||
export default content; | ||
} |