Skip to content

Commit

Permalink
Merge pull request #1482 from randomprofilename/graphql_federation_sc…
Browse files Browse the repository at this point in the history
…hemahost_fix

fix(federation): assignment GraphqlSchemaHost#schema in factory
  • Loading branch information
kamilmysliwiec committed Jun 18, 2021
2 parents ca0872b + f91c76b commit c526701
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/federation/graphql-federation.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
} from '../services';
import { extend } from '../utils';
import { transformSchema } from '../utils/transform-schema.util';
import { GraphQLSchemaHost } from '../graphql-schema.host';

@Injectable()
export class GraphQLFederationFactory {
Expand All @@ -39,6 +40,7 @@ export class GraphQLFederationFactory {
private readonly scalarsExplorerService: ScalarsExplorerService,
private readonly pluginsExplorerService: PluginsExplorerService,
private readonly gqlSchemaBuilder: GraphQLSchemaBuilder,
private readonly gqlSchemaHost: GraphQLSchemaHost,
) {}

async mergeOptions(
Expand All @@ -61,6 +63,8 @@ export class GraphQLFederationFactory {
schema = this.buildSchemaFromTypeDefs(options);
}

this.gqlSchemaHost.schema = schema;

return {
...options,
schema: await transformSchema(schema),
Expand Down
28 changes: 28 additions & 0 deletions tests/e2e/graphql-federation-schema-host.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { INestApplication } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import { AppModule } from '../graphql-federation/posts-service/federation-posts.module';
import { GraphQLSchemaHost } from '../../lib';
import { GraphQLSchema } from 'graphql';

describe('GraphQL federation GraphQLSchemaHost using', () => {
let app: INestApplication;

beforeEach(async () => {
const module = await Test.createTestingModule({
imports: [AppModule],
}).compile();

app = module.createNestApplication();
await app.init();
});

it(`GraphQLSchemaHost should contain schema`, () => {
const schemaHost = app.get(GraphQLSchemaHost)

expect(schemaHost.schema).toBeInstanceOf(GraphQLSchema)
});

afterEach(async () => {
await app.close();
});
});

0 comments on commit c526701

Please sign in to comment.