yarn add @pothos/core @graphql-yoga/node
Pothos is designed to be as type-safe as possible, to ensure everything works correctly, make sure
that your tsconfig.json
has strict
mode set to true:
{
"compilerOptions": {
"strict": true
}
}
import SchemaBuilder from '@pothos/core';
const builder = new SchemaBuilder({});
builder.queryType({
fields: (t) => ({
hello: t.string({
args: {
name: t.arg.string(),
},
resolve: (parent, { name }) => `hello, ${name || 'World'}`,
}),
}),
});
const schema = builder.toSchema();
The schema generated by Pothos is a standard graphql.js schema and can be used with several graphql
server implementations including @graphql-yoga/node
.
import { createServer } from '@graphql-yoga/node';
const server = createServer({
schema: builder.toSchema(),
});
server.start();