GiraphQL
Search…
Guide

Installing

1
yarn add @giraphql/core apollo-server
Copied!

Set up typescript

GiraphQL 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:
1
{
2
"compilerOptions": {
3
"strict": true
4
}
5
}
Copied!

Create a simple schema

1
import SchemaBuilder from '@giraphql/core';
2
3
const builder = new SchemaBuilder({});
4
5
builder.queryType({
6
fields: (t) => ({
7
hello: t.string({
8
args: {
9
name: t.arg.string(),
10
},
11
resolve: (parent, { name }) => `hello, ${name || 'World'}`,
12
}),
13
}),
14
});
15
16
const schema = builder.toSchema({});
Copied!

Create a server

The schema generated by GiraphQL is a standard graphql.js schema and can be used with several graphql server implementations including apollo server.
1
import { ApolloServer } from 'apollo-server';
2
3
const server = new ApolloServer({
4
schema,
5
});
6
7
server.listen(3000);
Copied!
Last modified 3d ago