Skip to content

Instantly share code, notes, and snippets.

@jbaxleyiii
Last active May 4, 2017 22:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbaxleyiii/e429f76ce29d06a8765a179f6bf1366c to your computer and use it in GitHub Desktop.
Save jbaxleyiii/e429f76ce29d06a8765a179f6bf1366c to your computer and use it in GitHub Desktop.
Heighliner [Functional GraphQL Server Framework]
import { graphql } from "graphql";
import { Schema, Type, Field, IntType, StringField } from "../schema";
it("creates an executable schema", async () => {
// build field resolvers
// these will implement Functor and Semigroup (and maybe more)
const code = Field(IntType, ({ code }) => code);
const message = StringField(({ message }) => message);
// create a type from defined fields
// these will implement Functor and Semigroup (and maybe more)
const Sample = Type("Sample", { code, message });
// build root query type
const sample = Field(Sample, () =>
Promise.resolve({
code: 200,
message: "hello world",
})
);
const query = Type("Query", { sample });
// build the schema
const schema = Schema(query);
// execute the test
const { data } = await graphql(schema, "{ sample { code message } }");
expect(data.sample).toEqual({
code: 200,
message: "hello world",
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment