@nestjs/graphql#GraphQLSchemaFactory TypeScript Examples

The following examples show how to use @nestjs/graphql#GraphQLSchemaFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: node-field.resolver.spec.ts    From nestjs-relay with MIT License 5 votes vote down vote up
describe('NodeField', () => {
  const resolver = new NodeResolver();

  describe('resolveNode', () => {
    describe('when not overridden', () => {
      it('should throw an error', async () => {
        const globalId = new ResolvedGlobalId({ type: 'Type', id: '1' });
        try {
          resolver.resolveNode(globalId);
        } catch (error) {
          expect(error).toEqual(new Error('Method not implemented.'));
        }
      });
    });
  });

  describe('schema', () => {
    let schema: GraphQLSchema;

    beforeAll(async () => {
      const app = await NestFactory.create(GraphQLSchemaBuilderModule);
      await app.init();

      const gqlSchemaFactory = app.get(GraphQLSchemaFactory);
      schema = await gqlSchemaFactory.create([NodeFieldResolver], [GlobalIdScalar]);
    });

    it('should contain the `Node` interface type', () => {
      const nodeType = schema.getType('Node');
      expect(nodeType).toBeDefined();
    });

    it('should contain the `node` field on the `Query` type', () => {
      const queryType = schema.getQueryType();
      expect(queryType).toBeDefined();

      const nodeField = queryType?.getFields()['node'];
      expect(nodeField).toBeDefined();
    });

    it('should contain the `nodes` field on the `Query` type', () => {
      const queryType = schema.getQueryType();
      expect(queryType).toBeDefined();

      const nodesField = queryType?.getFields()['nodes'];
      expect(nodesField).toBeDefined();
    });
  });
});