Last active
March 31, 2022 10:46
-
-
Save n1ru4l/f4318e39fc62303ef9430504267edb95 to your computer and use it in GitHub Desktop.
yoga tweet snippets
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
import {createServer, GraphQLYogaError } from "@graphql-yoga/node" | |
const server = createServer({ | |
schema: { | |
typeDefs: /* GraphQL */ ` | |
type Query { | |
foo: String | |
bar: String | |
} | |
`, | |
resolvers: { | |
Query: { | |
foo() { | |
throw new Error("This message will be masked.") | |
}, | |
bar() { | |
throw new GraphQLYogaError("This messages reaches the client.") | |
}, | |
} | |
} | |
} | |
}) | |
server.start() |
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
import { createTypesFactory, buildGraphQLSchema } from 'gqtx'; | |
import { createServer } from '@graphql-yoga/node' | |
const t = createTypesFactory<{}>() | |
const Query = t.queryType({ | |
fields: [ | |
t.field({ | |
name: 'hello', | |
type: t.String, | |
resolve: () => `Hello World!`, | |
}), | |
], | |
}); | |
const schema = buildGraphQLSchema({ | |
query: Query, | |
}); | |
const server = createServer({ schema }) | |
server.start() |
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
import { createServer } from '@graphql-yoga/node' | |
import { NextApiRequest, NextApiResponse } from 'next' | |
const server = createServer<{ | |
req: NextApiRequest | |
res: NextApiResponse | |
}>({ | |
cors: false, | |
endpoint: '/api/graphql', | |
}) | |
export const config = { | |
api: { | |
bodyParser: false, | |
externalResolver: true, | |
}, | |
} | |
export default server |
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
import { makeSchema, queryType } from 'nexus' | |
import { createServer } from '@graphql-yoga/node' | |
const Query = queryType({ | |
definition(t) { | |
t.string('hello', { resolve: () => 'hello world!' }) | |
} | |
}) | |
const schema = makeSchema({ | |
types: [Query] | |
}) | |
const server = createServer({ schema }) | |
server.start() |
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
import { createServer } from '@graphql-yoga/node' | |
import { useDepthLimit } from '@envelop/depth-limit' | |
import { useResponseCache } from '@envelop/response-cache' | |
import { useSentry } from '@envelop/sentry' | |
const server = createServer({ | |
plugins: [ | |
// set up some security rules | |
useDepthLimit({ | |
maxDepth: 10 | |
}), | |
// speed up our server with a response cache | |
useResponseCache(), | |
// report unexpected errors to sentry | |
useSentry(), | |
] | |
}) | |
server.start() |
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
import SchemaBuilder from '@pothos/core'; | |
import { createServer } from '@graphql-yoga/node' | |
const builder = new SchemaBuilder({}); | |
builder.queryType({ | |
fields: (t) => ({ | |
hello: t.string({ | |
resolve: () => `Hello World!`, | |
}), | |
}), | |
}); | |
const schema = builder.toSchema({}); | |
const server = createServer({ schema }) | |
server.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment