@ailo/graphql-server

Ailo TypeScript starter

Usage no npm install needed!

<script type="module">
  import ailoGraphqlServer from 'https://cdn.skypack.dev/@ailo/graphql-server';
</script>

README

@ailo/graphql-server

Ailo GraphQL server to be used in Ailo node.js services. Requires Koa as a HTTP server.

Usage

yarn add @ailo/graphql-server @apollo/federation graphql
yarn add -D apollo-server-testing
// src/api/graphqlServer.ts
import { Logger } from "local/app/utils/logger";
import { monitoring } from "local/app/utils/monitoring";
import { GraphQLServer } from "@ailo/graphql-server";

export const consumerGraphqlServer = new GraphQLServer({
  schema: buildFederatedSchema([...]),
  logger: Logger.logAs(`gql.consumer`),
  monitoring,
});

// src/app/app.ts
const app = new Koa();
consumerGraphqlServer.applyMiddleware({ app, path: "/consumer/graphql" });

Testing your server

// src/api/some-query.integration.test.ts
import { mockGraphQLServer, gql } from "@ailo/graphql-server";
import { modules } from "./schema";

it("updateName mutation updates the name", async () => {
  const { query } = mockGraphQLServer({ modules });
  const response = await query({
    query: gql`
      mutation($name: String!) {
        updateName(name: $name) {
          name
        }
      }
    `,
    variables: {
      name: "new name",
    },
  });
  expect(response.data.updateName).toMatchObject({
    name: "new name",
  });
});

Development

yarn
yarn start

Testing

yarn lint # prettier and eslint
yarn test # unit tests
yarn test:watch # unit tests in watch mode

E2E Test

yarn test:e2e
graphqurl http://localhost:8080/consumer/graphql -i

Releasing

yarn release # will automatically ask you about version bump, run tests and build, and push new version to git & npm