File tree Expand file tree Collapse file tree 2 files changed +41
-2
lines changed
commonMain/kotlin/com/apollographql/apollo/ast/internal
commonTest/kotlin/com/apollographql/apollo/graphql/ast/test Expand file tree Collapse file tree 2 files changed +41
-2
lines changed Original file line number Diff line number Diff line change @@ -318,15 +318,20 @@ private fun List<GQLSchemaExtension>.getImports(
318
318
val schemaExtensions = this
319
319
320
320
val imports = mutableListOf<Import >()
321
-
321
+ val linkForeignSchema = ForeignSchema (" link" , " v1.0" , linkDefinitions())
322
+ val linkImport = Import (linkForeignSchema, linkForeignSchema.definitions, mapOf (" link" to " link" ))
322
323
schemaExtensions.forEach { schemaExtension ->
323
324
schemaExtension.directives.forEach eachDirective@{ gqlDirective ->
324
325
if (gqlDirective.name == " link" ) {
326
+ if (! imports.contains(linkImport)) {
327
+ imports.add(linkImport)
328
+ }
329
+
325
330
/* *
326
331
* Validate `@link` using a very minimal schema.
327
332
* This ensure we can safely cast the arguments below
328
333
*/
329
- val minimalSchema = builtinDefinitions + linkDefinitions()
334
+ val minimalSchema = builtinDefinitions + linkForeignSchema.definitions
330
335
val scope = DefaultValidationScope (
331
336
minimalSchema.filterIsInstance<GQLTypeDefinition >().associateBy { it.name },
332
337
minimalSchema.filterIsInstance<GQLDirectiveDefinition >().associateBy { it.name },
Original file line number Diff line number Diff line change @@ -73,6 +73,40 @@ class SchemaTest {
73
73
assertEquals(" cacheControl" , schema.originalDirectiveName(" cacheControl" ))
74
74
}
75
75
76
+ @Test
77
+ fun multipleImportDirectives () {
78
+ // language=graphql
79
+ val schemaString = """
80
+ extend schema
81
+ @link(url: "https://specs.apollo.dev/cache/v0.1/", import: ["@cacheControl"])
82
+ @link(url: "https://example.com/example/v0.1/", import: ["@example"])
83
+ extend schema
84
+ @link(url: "https://example.com/example2/v0.1/", import: ["@example2"])
85
+
86
+ type Query {
87
+ foo: Int @cacheControl(maxAge: 100) @example @example2
88
+ }
89
+ """ .trimIndent()
90
+
91
+ val schema = schemaString.toGQLDocument().validateAsSchema(
92
+ SchemaValidationOptions (
93
+ addKotlinLabsDefinitions = false ,
94
+ foreignSchemas = listOf (
95
+ cacheControlSchema,
96
+ ForeignSchema (" example" , " v0.1" ,
97
+ listOf (" directive @example on FIELD_DEFINITION" .parseAsGQLDocument().getOrThrow().definitions.single())
98
+ ),
99
+ ForeignSchema (" example2" , " v0.1" ,
100
+ listOf (" directive @example2 on FIELD_DEFINITION" .parseAsGQLDocument().getOrThrow().definitions.single())
101
+ )
102
+ )
103
+ )
104
+ ).getOrThrow()
105
+
106
+ assertEquals(" cacheControl" , schema.originalDirectiveName(" cacheControl" ))
107
+ assertEquals(" example" , schema.originalDirectiveName(" example" ))
108
+ }
109
+
76
110
@Test
77
111
fun unknownSchemaFails () {
78
112
// language=graphql
You can’t perform that action at this time.
0 commit comments