Skip to content

Commit

Permalink
Adding federation tag directive to ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
kmoore-intuit committed Feb 27, 2024
1 parent 8f7a2ee commit 3b85686
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/resources/federation_built_in_directives.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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<ServiceProvider> 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
}
}

0 comments on commit 3b85686

Please sign in to comment.