|
15 | 15 | NonNullTypeNode, |
16 | 16 | NullValueNode, |
17 | 17 | Undefined, |
| 18 | +) |
| 19 | +from graphql import __version__ as graphql_version |
| 20 | +from graphql import ( |
18 | 21 | build_ast_schema, |
19 | 22 | parse, |
20 | 23 | print_ast, |
21 | 24 | ) |
22 | 25 | from graphql.utilities import get_introspection_query |
| 26 | +from packaging import version |
23 | 27 |
|
24 | 28 | from gql import Client, gql |
25 | 29 | from gql.dsl import ( |
@@ -1084,6 +1088,50 @@ def test_get_introspection_query_ast(option): |
1084 | 1088 | ) |
1085 | 1089 |
|
1086 | 1090 |
|
| 1091 | +@pytest.mark.skipif( |
| 1092 | + version.parse(graphql_version) < version.parse("3.3.0a7"), |
| 1093 | + reason="Requires graphql-core >= 3.3.0a7", |
| 1094 | +) |
| 1095 | +@pytest.mark.parametrize("option", [True, False]) |
| 1096 | +def test_get_introspection_query_ast_is_one_of(option): |
| 1097 | + |
| 1098 | + introspection_query = print_ast( |
| 1099 | + gql( |
| 1100 | + get_introspection_query( |
| 1101 | + input_value_deprecation=option, |
| 1102 | + ) |
| 1103 | + ).document |
| 1104 | + ) |
| 1105 | + |
| 1106 | + # Because the option does not exist yet in graphql-core, |
| 1107 | + # we add it manually here for now |
| 1108 | + if option: |
| 1109 | + introspection_query = introspection_query.replace( |
| 1110 | + "fields", |
| 1111 | + "isOneOf\n fields", |
| 1112 | + ) |
| 1113 | + |
| 1114 | + dsl_introspection_query = get_introspection_query_ast( |
| 1115 | + input_value_deprecation=option, |
| 1116 | + input_object_one_of=option, |
| 1117 | + type_recursion_level=9, |
| 1118 | + ) |
| 1119 | + |
| 1120 | + assert introspection_query == print_ast(dsl_introspection_query) |
| 1121 | + |
| 1122 | + |
| 1123 | +@pytest.mark.skipif( |
| 1124 | + version.parse(graphql_version) >= version.parse("3.3.0a7"), |
| 1125 | + reason="Test only for older graphql-core versions < 3.3.0a7", |
| 1126 | +) |
| 1127 | +def test_get_introspection_query_ast_is_one_of_not_implemented_yet(): |
| 1128 | + |
| 1129 | + with pytest.raises(NotImplementedError): |
| 1130 | + get_introspection_query_ast( |
| 1131 | + input_object_one_of=True, |
| 1132 | + ) |
| 1133 | + |
| 1134 | + |
1087 | 1135 | def test_typename_aliased(ds): |
1088 | 1136 | query = """ |
1089 | 1137 | hero { |
|
0 commit comments