-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Local schema improvements (hmr and printing) (#1203)
Co-authored-by: Alec Aivazis <[email protected]>
- Loading branch information
1 parent
f6ef67e
commit a6a5147
Showing
14 changed files
with
181 additions
and
113 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
projects: | ||
default: | ||
schema: | ||
- ./$houdini/graphql/schema.graphql | ||
documents: | ||
- '**/*.gql' | ||
- '**/*.jsx' | ||
- '**/*.tsx' | ||
- ./$houdini/graphql/documents.gql |
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,95 +1,6 @@ | ||
import { makeExecutableSchema } from '@graphql-tools/schema' | ||
|
||
const typeDefs = /* GraphQL */ ` | ||
type Query { | ||
welcome: String! | ||
links(delay: Int): [Link!]! | ||
sponsors: [Sponsor!]! | ||
giveMeAnError: String | ||
} | ||
type Mutation { | ||
hello(name: String!): String! | ||
} | ||
type Link { | ||
name: String | ||
url: String | ||
} | ||
type Sponsor { | ||
login: String! | ||
name: String! | ||
avatarUrl: String! | ||
websiteUrl: String | ||
tiersTitle: String! | ||
} | ||
` | ||
|
||
const resolvers = { | ||
Query: { | ||
welcome: () => 'Welcome to Houdini 🎩', | ||
links: async (_: any, args: { delay?: number }) => { | ||
if (args.delay) { | ||
await new Promise((resolve) => setTimeout(resolve, args.delay)) | ||
} | ||
return [ | ||
{ name: 'GitHub', url: 'https://github.com/HoudiniGraphql/houdini' }, | ||
{ name: 'Documentation', url: 'https://houdinigraphql.com/' }, | ||
{ name: 'Discord', url: 'https://discord.gg/Gd8vfvxpsD' }, | ||
] | ||
}, | ||
sponsors: async () => { | ||
const res = await fetch( | ||
'https://raw.githubusercontent.com/HoudiniGraphql/sponsors/main/generated/sponsors.json' | ||
) | ||
const jsonData = await res.json() | ||
|
||
function getTier(value: number) { | ||
if (value >= 1500) { | ||
return 'Wizard' | ||
} | ||
if (value >= 500) { | ||
return 'Mage' | ||
} | ||
if (value >= 25) { | ||
return "Magician's Apprentice" | ||
} | ||
if (value >= 10) { | ||
return 'Supportive Muggle' | ||
} | ||
return 'Past Sponsors' | ||
} | ||
|
||
return jsonData.map( | ||
(c: { | ||
sponsor: { | ||
login: string | ||
name: string | ||
avatarUrl: string | ||
websiteUrl: string | ||
} | ||
monthlyDollars: number | ||
}) => { | ||
return { | ||
login: c.sponsor.login, | ||
name: c.sponsor.name, | ||
avatarUrl: c.sponsor.avatarUrl, | ||
websiteUrl: c.sponsor.websiteUrl, | ||
tiersTitle: getTier(c.monthlyDollars), | ||
} | ||
} | ||
) | ||
}, | ||
giveMeAnError: () => { | ||
throw new Error(`Yes, I'm an error!`) | ||
}, | ||
}, | ||
Mutation: { | ||
hello: (_: any, args: { name: string }) => { | ||
return `👋 Hey, hello ${args.name}! ` | ||
}, | ||
}, | ||
} | ||
import { resolvers } from './resolvers' | ||
import { typeDefs } from './typeDefs' | ||
|
||
export default makeExecutableSchema({ typeDefs, resolvers }) |
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 @@ | ||
export const dico = { HELLO: `👋 Hey, hello` } |
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,5 @@ | ||
export const extra = /* GraphQL */ ` | ||
extend type Query { | ||
welcomeTooEveryone: 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,67 @@ | ||
import { dico } from './dico' | ||
|
||
export const resolvers = { | ||
Query: { | ||
welcome: () => 'Welcome to Houdini 🎩', | ||
links: async (_: any, args: { delay?: number }) => { | ||
if (args.delay) { | ||
await new Promise((resolve) => setTimeout(resolve, args.delay)) | ||
} | ||
return [ | ||
{ name: 'GitHub', url: 'https://github.com/HoudiniGraphql/houdini' }, | ||
{ name: 'Documentation', url: 'https://houdinigraphql.com/' }, | ||
{ name: 'Discord', url: 'https://discord.gg/Gd8vfvxpsD' }, | ||
] | ||
}, | ||
sponsors: async () => { | ||
const res = await fetch( | ||
'https://raw.githubusercontent.com/HoudiniGraphql/sponsors/main/generated/sponsors.json' | ||
) | ||
const jsonData = await res.json() | ||
|
||
function getTier(value: number) { | ||
if (value >= 1500) { | ||
return 'Wizard' | ||
} | ||
if (value >= 500) { | ||
return 'Mage' | ||
} | ||
if (value >= 25) { | ||
return "Magician's Apprentice" | ||
} | ||
if (value >= 10) { | ||
return 'Supportive Muggle' | ||
} | ||
return 'Past Sponsors' | ||
} | ||
|
||
return jsonData.map( | ||
(c: { | ||
sponsor: { | ||
login: string | ||
name: string | ||
avatarUrl: string | ||
websiteUrl: string | ||
} | ||
monthlyDollars: number | ||
}) => { | ||
return { | ||
login: c.sponsor.login, | ||
name: c.sponsor.name, | ||
avatarUrl: c.sponsor.avatarUrl, | ||
websiteUrl: c.sponsor.websiteUrl, | ||
tiersTitle: getTier(c.monthlyDollars), | ||
} | ||
} | ||
) | ||
}, | ||
giveMeAnError: () => { | ||
throw new Error(`Yes, I'm an error!`) | ||
}, | ||
}, | ||
Mutation: { | ||
hello: (_: any, args: { name: string }) => { | ||
return `${dico.HELLO} ${args.name}!` | ||
}, | ||
}, | ||
} |
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,25 @@ | ||
export const typeDefs = /* GraphQL */ ` | ||
type Query { | ||
welcome: String! | ||
links(delay: Int): [Link!]! | ||
sponsors: [Sponsor!]! | ||
giveMeAnError: String | ||
} | ||
type Mutation { | ||
hello(name: String!): String! | ||
} | ||
type Link { | ||
name: String | ||
url: String | ||
} | ||
type Sponsor { | ||
login: String! | ||
name: String! | ||
avatarUrl: String! | ||
websiteUrl: String | ||
tiersTitle: 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
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
Oops, something went wrong.