8.0.172-ailo-string-resolver • Published 1 year ago

@ailo/graphql-server v8.0.172-ailo-string-resolver

Weekly downloads
140
License
MIT
Repository
github
Last release
1 year ago

@ailo/graphql-server

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

Usage

Setup

  1. Install dependencies

    yarn add @ailo/graphql-server graphql
    yarn add -D apollo-server-testing
  2. Setup GraphQL Server

    // src/api/graphqlServer.ts
    import { Logger } from "local/app/utils/logger";
    import { monitoring } from "local/app/utils/monitoring";
    import { GraphQLServer, BaseCommonSchemaModule, AuthZCommonSchemaModule } from "@ailo/graphql-server";
    
    export const consumerGraphqlServer = new GraphQLServer({
      schema: { modules: [BaseCommonSchemaModule, AuthZCommonSchemaModule, ...] },
      logger: Logger.logAs(`gql.consumer`),
      monitoring,
    });
    
    // src/app/app.ts
    import Koa from "koa";
    import Router from "koa-router";
    import { createServer } from "http";
    
    const app = new Koa();
    const httpServer = createServer(app.callback());
    const router = new Router();
    
    await consumerGraphqlServer.apolloServer.start();
    
    router.all(
     "/consumer/graphql",
     ailoKoaMiddleware(consumerGraphqlServer.apolloServer)
    )
    
    app.use(router.routes());
  3. Setup @graphql-codegen/cli:

    • add following schema files to the beginning of your generates[*].schema[]:

      "schema": [
        "node_modules/@ailo/graphql-server/build/module/commonSchemaModules/base.js",
        "node_modules/@ailo/graphql-server/build/module/commonSchemaModules/authz.js",
        ...
      ]
    • add following scalars to config.scalars:

      "scalars": {
        "TimeZone": "string",
        "AiloRN": "@ailo/ailorn#AiloRN",
      },
  • if you use SortDirection in your schema, add the following to each of your schema under generates[*].config.enumValues:

    "config": {
      "enumValues": {
         "SortDirection": "@ailo/graphql-server#SortDirection",
         ...
      }
    }

How to write integration tests for code using @ailo/graphql-server ? (example)

// 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",
  });
});

How to resolve ActionInitiator ? (example)

import { gql, resolveActionInitiatorFromAiloRN } from "@ailo/graphql-server";

const typeDefs = gql`
  type Supplier {
    createdBy: ActionInitiator
    modifiedBy: ActionInitiator
    archivedBy: ActionInitiator
  }
`;

const resolvers: GraphQLResolvers = {
  Supplier: {
    createdBy: (supplier) =>
      resolveActionInitiatorFromAiloRN(supplier.createdBy),
    modifiedBy: (supplier) =>
      resolveActionInitiatorFromAiloRN(supplier.modifiedBy),
    archivedBy: (supplier) =>
      resolveActionInitiatorFromAiloRN(supplier.archivedBy),
  },
};

export const module = { typeDefs, resolvers };

Development

yarn
yarn start

Testing

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

Releasing

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

1 year ago

8.0.10

1 year ago

8.0.9

1 year ago

8.0.8

1 year ago

8.0.7

1 year ago

8.0.6

1 year ago

8.0.5

2 years ago

8.0.4

2 years ago

8.0.1

2 years ago

8.0.3

2 years ago

8.0.2

2 years ago

8.0.0-alpha5

2 years ago

8.0.0-alpha2

2 years ago

8.0.0-alpha4

2 years ago

8.0.0-alpha3

2 years ago

8.0.0

2 years ago

8.0.0-alpha

2 years ago

7.0.0

2 years ago

7.0.1

2 years ago

5.0.3

2 years ago

5.0.2

2 years ago

4.0.5

2 years ago

4.0.4

2 years ago

4.0.1

2 years ago

4.0.3

2 years ago

4.0.2

2 years ago

3.1.5

2 years ago

3.1.4

2 years ago

3.1.3

3 years ago

3.1.2

3 years ago

3.1.1

3 years ago

3.1.0

3 years ago

3.0.4

3 years ago

3.0.3

3 years ago

3.0.2

3 years ago

3.0.1

3 years ago

2.1.8

4 years ago

2.1.7

4 years ago

2.1.9

4 years ago

2.1.10

4 years ago

2.1.6

4 years ago

2.1.4

4 years ago

2.1.3

4 years ago

2.1.5

4 years ago

2.1.2

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.0

4 years ago

1.16.1

4 years ago

1.16.0

4 years ago

1.15.0

4 years ago

1.14.0

4 years ago

1.13.0

4 years ago

1.12.2

4 years ago

1.12.1

4 years ago

1.12.0

4 years ago

1.11.0

4 years ago

1.10.2

4 years ago

1.10.1

4 years ago

1.10.0

4 years ago

1.9.0

4 years ago

1.7.3

4 years ago

1.7.2

4 years ago

1.8.0

4 years ago

1.7.1

4 years ago

1.7.0

4 years ago

1.6.6

4 years ago

1.6.5

4 years ago

1.6.4

4 years ago

1.6.3

4 years ago

1.6.2

5 years ago

1.6.1

5 years ago

1.6.0

5 years ago

1.5.1

5 years ago

1.5.0

5 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago