Skip to content

Commit

Permalink
Refactor and remove extraneous test
Browse files Browse the repository at this point in the history
  • Loading branch information
eddeee888 committed Aug 20, 2024
1 parent 61edc69 commit a019f95
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -793,36 +793,4 @@ describe('TypeScript Resolvers Plugin + Apollo Federation', () => {
}
`);
});

it('meta - does not generate federation meta if federation config is false', async () => {
const federatedSchema = /* GraphQL */ `
scalar _FieldSet
directive @key(fields: _FieldSet!, resolvable: Boolean) repeatable on OBJECT | INTERFACE
type Query {
allUsers: [User]
}
type User @key(fields: "id") {
id: ID!
name: String
username: String
}
`;

const result = await plugin(buildSchema(federatedSchema), [], {}, { outputFile: '' });

expect(result.meta?.generatedResolverTypes).toMatchInlineSnapshot(`
Object {
"Query": Object {
"federation": undefined,
"name": "QueryResolvers",
},
"User": Object {
"federation": undefined,
"name": "UserResolvers",
},
}
`);
});
});
10 changes: 3 additions & 7 deletions packages/utils/plugins-helpers/src/federation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ export function addFederationReferencesToSchema(schema: GraphQLSchema): GraphQLS
[MapperKind.OBJECT_TYPE]: type => {
const objectTypeFederationDetails = checkObjectTypeFederationDetails(type, schema);

if (!objectTypeFederationDetails) {
return type;
}

if (objectTypeFederationDetails.resolvableKeyDirectives.length === 0) {
if (!objectTypeFederationDetails || objectTypeFederationDetails.resolvableKeyDirectives.length === 0) {
return type;
}

Expand Down Expand Up @@ -290,7 +286,7 @@ export class ApolloFederation {
export function checkObjectTypeFederationDetails(
node: ObjectTypeDefinitionNode | GraphQLObjectType,
schema: GraphQLSchema
): { keyDirectives: readonly ConstDirectiveNode[]; resolvableKeyDirectives: readonly ConstDirectiveNode[] } | false {
): { resolvableKeyDirectives: readonly ConstDirectiveNode[] } | false {
const {
name: { value: name },
directives,
Expand All @@ -316,7 +312,7 @@ export function checkObjectTypeFederationDetails(
return true;
});

return { keyDirectives, resolvableKeyDirectives };
return { resolvableKeyDirectives };
}

/**
Expand Down

0 comments on commit a019f95

Please sign in to comment.