Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(schema-first): merge duplicate IQuery interface #2353

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/apollo/tests/e2e/generated-definitions.spec.ts
Expand Up @@ -339,4 +339,23 @@ describe('Generated Definitions', () => {
afterEach(async () => {
await app.close();
});

it('should generate for a federated graph with partial query definition', async () => {
const outputFile = generatedDefinitions(
'federation-partial-query.test-definitions.ts',
);
const factory = new GraphQLFederationDefinitionsFactory();
await factory.generate({
typePaths: [generatedDefinitions('federation-partial-query.graphql')],
path: outputFile,
outputAs: 'interface',
});

expect(
await readFile(
generatedDefinitions('federation-partial-query.fixture.ts'),
'utf8',
),
).toBe(await readFile(outputFile, 'utf8'));
});
});
@@ -0,0 +1,15 @@

/*
* -------------------------------------------------------
* THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY)
* -------------------------------------------------------
*/

/* tslint:disable */
/* eslint-disable */

export interface IQuery {
foo(): Nullable<boolean> | Promise<Nullable<boolean>>;
}

type Nullable<T> = T | null;
@@ -0,0 +1,3 @@
extend type Query {
foo: Boolean
}
Expand Up @@ -3,6 +3,7 @@ import { gql } from 'graphql-tag';
import { DefinitionsGeneratorOptions } from '../graphql-ast.explorer';
import { GraphQLDefinitionsFactory } from '../graphql-definitions.factory';
import { extend } from '../utils';
import { mergeTypeDefs } from '@graphql-tools/merge';

export class GraphQLFederationDefinitionsFactory extends GraphQLDefinitionsFactory {
protected async exploreAndEmit(
Expand Down Expand Up @@ -35,9 +36,17 @@ export class GraphQLFederationDefinitionsFactory extends GraphQLDefinitionsFacto
resolvers: {},
},
]);

const mergedDefinition = mergeTypeDefs([printSubgraphSchema(schema)], {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a comment explaining why this is needed? (with a link to the original issue)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that such a comment should be here. I'll add it.

useSchemaDefinition: false,
throwOnConflict: true,
commentDescriptions: true,
reverseDirectives: true,
});

const tsFile = await this.gqlAstExplorer.explore(
gql`
${printSubgraphSchema(schema)}
${mergedDefinition}
`,
path,
outputAs,
Expand Down