Skip to content

Commit 4ff2092

Browse files
dariuszkucsmyrick
authored andcommitted
[federation] federated directives integration tests (#548)
1 parent 18a5f9b commit 4ff2092

34 files changed

+1526
-367
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2020 Expedia, Inc
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.expediagroup.graphql.federation.data.integration.key.failure._1
18+
19+
import com.expediagroup.graphql.federation.directives.ExtendsDirective
20+
import com.expediagroup.graphql.federation.directives.ExternalDirective
21+
22+
/*
23+
# example of invalid federated type - missing @key directive
24+
type FederatedMissingKey @extends {
25+
description: String!
26+
id: String! @external
27+
}
28+
*/
29+
@ExtendsDirective
30+
data class FederatedMissingKey(@ExternalDirective val id: String, val description: String)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2020 Expedia, Inc
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.expediagroup.graphql.federation.data.integration.key.failure._2
18+
19+
import com.expediagroup.graphql.federation.directives.FieldSet
20+
import com.expediagroup.graphql.federation.directives.KeyDirective
21+
import io.mockk.mockk
22+
23+
/*
24+
# example invalid usage of @key directive - does not specify any fields
25+
type KeyMissingFieldSelection @key(fields : "") {
26+
description: String!
27+
id: String!
28+
}
29+
*/
30+
@KeyDirective(FieldSet(""))
31+
data class KeyMissingFieldSelection(val id: String, val description: String)
32+
33+
class KeyMissingFieldSelectionQuery {
34+
fun keyQuery(): KeyMissingFieldSelection = mockk()
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2020 Expedia, Inc
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.expediagroup.graphql.federation.data.integration.key.failure._3
18+
19+
import com.expediagroup.graphql.federation.directives.FieldSet
20+
import com.expediagroup.graphql.federation.directives.KeyDirective
21+
import io.mockk.mockk
22+
23+
/*
24+
# example invalid usage of @key directive - references non-existent field
25+
type InvalidKey @key(fields : "id") {
26+
description: String!
27+
productId: String!
28+
}
29+
*/
30+
@KeyDirective(fields = FieldSet("id"))
31+
data class InvalidKey(val productId: String, val description: String)
32+
33+
class InvalidKeyQuery {
34+
fun keyQuery(): InvalidKey = mockk()
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2020 Expedia, Inc
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.expediagroup.graphql.federation.data.integration.key.failure._4
18+
19+
import com.expediagroup.graphql.federation.directives.ExternalDirective
20+
import com.expediagroup.graphql.federation.directives.FieldSet
21+
import com.expediagroup.graphql.federation.directives.KeyDirective
22+
import io.mockk.mockk
23+
24+
/*
25+
# example usage of invalid type - external type specified in local object
26+
type BaseKeyReferencingExternalFields @key(fields : "id") {
27+
description: String!
28+
id: String! @external
29+
}
30+
*/
31+
@KeyDirective(fields = FieldSet("id"))
32+
data class BaseKeyReferencingExternalFields(@ExternalDirective val id: String, val description: String)
33+
34+
class BaseKeyReferencingExternalFieldsQuery {
35+
fun keyQuery(): BaseKeyReferencingExternalFields = mockk()
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2020 Expedia, Inc
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.expediagroup.graphql.federation.data.integration.key.failure._5
18+
19+
import com.expediagroup.graphql.federation.directives.ExtendsDirective
20+
import com.expediagroup.graphql.federation.directives.FieldSet
21+
import com.expediagroup.graphql.federation.directives.KeyDirective
22+
23+
/*
24+
# example invalid usage of @key directive - extended type references local field
25+
type ExternalKeyReferencingLocalField @extends @key(fields : "id") {
26+
description: String!
27+
id: String!
28+
}
29+
*/
30+
@KeyDirective(fields = FieldSet("id"))
31+
@ExtendsDirective
32+
data class ExternalKeyReferencingLocalField(val id: String, val description: String)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2020 Expedia, Inc
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.expediagroup.graphql.federation.data.integration.key.failure._6
18+
19+
import com.expediagroup.graphql.federation.directives.FieldSet
20+
import com.expediagroup.graphql.federation.directives.KeyDirective
21+
import io.mockk.mockk
22+
23+
/*
24+
# example usage of invalid @key directive - field set references a list
25+
type KeyReferencingList @key(fields : "id") {
26+
description: String!
27+
id: [String!]!
28+
}
29+
*/
30+
@KeyDirective(fields = FieldSet("id"))
31+
data class KeyReferencingList(val id: List<String>, val description: String)
32+
33+
class KeyReferencingListQuery {
34+
fun keyQuery(): KeyReferencingList = mockk()
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2020 Expedia, Inc
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.expediagroup.graphql.federation.data.integration.key.failure._7
18+
19+
import com.expediagroup.graphql.federation.directives.FieldSet
20+
import com.expediagroup.graphql.federation.directives.KeyDirective
21+
import io.mockk.mockk
22+
23+
/*
24+
# example usage of invalid @key directive - field set references interface
25+
type KeyReferencingInterface @key(fields : "id") {
26+
description: String!
27+
id: KeyInterface!
28+
}
29+
30+
interface KeyInterface {
31+
id: String!
32+
}
33+
*/
34+
@KeyDirective(fields = FieldSet("id"))
35+
data class KeyReferencingInterface(val id: KeyInterface, val description: String)
36+
37+
interface KeyInterface {
38+
val id: String
39+
}
40+
41+
class KeyReferencingInterfaceQuery {
42+
fun keyQuery(): KeyReferencingInterface = mockk()
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2020 Expedia, Inc
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.expediagroup.graphql.federation.data.integration.key.failure._8
18+
19+
import com.expediagroup.graphql.federation.directives.FieldSet
20+
import com.expediagroup.graphql.federation.directives.KeyDirective
21+
import io.mockk.mockk
22+
23+
/*
24+
# example invalid usage of @key directive - field set references a union
25+
type KeyReferencingUnion @key(fields : "id") {
26+
description: String!
27+
id: KeyUnion!
28+
}
29+
30+
type Key {
31+
id: String!
32+
}
33+
34+
union KeyUnion = Key
35+
*/
36+
@KeyDirective(fields = FieldSet("id"))
37+
data class KeyReferencingUnion(val id: KeyUnion, val description: String)
38+
39+
interface KeyUnion
40+
41+
@Suppress("UnusedPrivateClass")
42+
data class Key(val id: String) : KeyUnion
43+
44+
class KeyReferencingUnionQuery {
45+
fun keyQuery(): KeyReferencingUnion = mockk()
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2020 Expedia, Inc
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.expediagroup.graphql.federation.data.integration.key.failure._9
18+
19+
import com.expediagroup.graphql.federation.directives.FieldSet
20+
import com.expediagroup.graphql.federation.directives.KeyDirective
21+
import io.mockk.mockk
22+
23+
/*
24+
# example invalid usage of @key directive - field set references complex key on scalar
25+
type NestedKeyReferencingScalar @key(fields : "id { uuid }") {
26+
description: String!
27+
id: String!
28+
}
29+
*/
30+
@KeyDirective(fields = FieldSet("id { uuid }"))
31+
data class NestedKeyReferencingScalar(val id: String, val description: String)
32+
33+
class NestedKeyReferencingScalarQuery {
34+
fun keyQuery(): NestedKeyReferencingScalar = mockk()
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2020 Expedia, Inc
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.expediagroup.graphql.federation.data.integration.key.success._1
18+
19+
import com.expediagroup.graphql.federation.directives.FieldSet
20+
import com.expediagroup.graphql.federation.directives.KeyDirective
21+
import io.mockk.mockk
22+
23+
/*
24+
# example usage of a valid @key directive referencing single field on a local type
25+
type SimpleKey @key(fields : "id") {
26+
description: String!
27+
id: String!
28+
}
29+
*/
30+
@KeyDirective(fields = FieldSet("id"))
31+
data class SimpleKey(val id: String, val description: String)
32+
33+
class SimpleKeyQuery {
34+
fun simpleKey(): SimpleKey = mockk()
35+
}

0 commit comments

Comments
 (0)