From 3b85686eab2c3a816820581c634a2dc4a39df0a5 Mon Sep 17 00:00:00 2001 From: kmoore15 Date: Tue, 27 Feb 2024 16:26:34 -0500 Subject: [PATCH] Adding federation tag directive to ignore --- .../federation_built_in_directives.graphqls | 1 + .../IgnoredDirectiveSpec.groovy | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 src/test/groovy/com/intuit/graphql/orchestrator/federationdirectives/ignoredDirectives/IgnoredDirectiveSpec.groovy diff --git a/src/main/resources/federation_built_in_directives.graphqls b/src/main/resources/federation_built_in_directives.graphqls index d326593c..d00a3c05 100644 --- a/src/main/resources/federation_built_in_directives.graphqls +++ b/src/main/resources/federation_built_in_directives.graphqls @@ -6,3 +6,4 @@ directive @external on FIELD_DEFINITION directive @provides(fields: String!) on FIELD_DEFINITION directive @requires(fields: _FieldSet!) on FIELD_DEFINITION +directive @tag(name: String!) repeatable on FIELD_DEFINITION | INTERFACE | OBJECT | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION diff --git a/src/test/groovy/com/intuit/graphql/orchestrator/federationdirectives/ignoredDirectives/IgnoredDirectiveSpec.groovy b/src/test/groovy/com/intuit/graphql/orchestrator/federationdirectives/ignoredDirectives/IgnoredDirectiveSpec.groovy new file mode 100644 index 00000000..373b4c6f --- /dev/null +++ b/src/test/groovy/com/intuit/graphql/orchestrator/federationdirectives/ignoredDirectives/IgnoredDirectiveSpec.groovy @@ -0,0 +1,42 @@ +package com.intuit.graphql.orchestrator.federationdirectives.ignoredDirectives + +import com.intuit.graphql.orchestrator.ServiceProvider +import com.intuit.graphql.orchestrator.schema.RuntimeGraph +import com.intuit.graphql.orchestrator.stitching.SchemaStitcher +import graphql.schema.GraphQLFieldDefinition +import helpers.BaseIntegrationTestSpecification + +class IgnoredDirectiveSpec extends BaseIntegrationTestSpecification { + def "Successful stitching fields with tags"() { + given: + String SCHEMA_WITH_TAGS = ''' + type Query { + multipleTagField(id: String): String @tag(name: "tag1") @tag(name: "tag2") + singleTagField: String @tag(name: "soloTag") + noTagField: String + } + ''' + + ServiceProvider tagProvider = createQueryMatchingService("TAG_SERVICE_PROVIDER", + ServiceProvider.ServiceType.FEDERATION_SUBGRAPH, SCHEMA_WITH_TAGS, null) + List services = List.of(tagProvider) + + when: + RuntimeGraph actualRuntimeGraph = SchemaStitcher.newBuilder() + .services(services).build().stitchGraph() + + then: + actualRuntimeGraph != null + actualRuntimeGraph.addtionalDirectives.stream().anyMatch { it -> it.name == "tag" } + GraphQLFieldDefinition multipleTagGqlDef = actualRuntimeGraph.executableSchema.queryType.getFieldDefinition("multipleTagField") + multipleTagGqlDef.directives.size() == 2 + multipleTagGqlDef.getDirectives().get(0).getArgument("name").argumentValue.getValue() == "tag1" + multipleTagGqlDef.getDirectives().get(1).getArgument("name").argumentValue.getValue() == "tag2" + + GraphQLFieldDefinition singleTagGqlDef = actualRuntimeGraph.executableSchema.queryType.getFieldDefinition("singleTagField") + singleTagGqlDef.directives.size() == 1 + singleTagGqlDef.getDirectives().get(0).getArgument("name").argumentValue.getValue() == "soloTag" + + actualRuntimeGraph.executableSchema.queryType.getFieldDefinition("noTagField").directives.size() == 0 + } +} \ No newline at end of file