Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for federation versions up to 2.6 #1158

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions ariadne/contrib/federation/definitions/fed_v2.4.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#
# https://specs.apollo.dev/federation/v2.0/federation-v2.0.graphql
#

directive @key(fields: FieldSet!, resolvable: Boolean = true) repeatable on OBJECT | INTERFACE
directive @requires(fields: FieldSet!) on FIELD_DEFINITION
directive @provides(fields: FieldSet!) on FIELD_DEFINITION
directive @external on OBJECT | FIELD_DEFINITION
directive @extends on OBJECT | INTERFACE
directive @override(from: String!) on FIELD_DEFINITION
directive @inaccessible on
| FIELD_DEFINITION
| OBJECT
| INTERFACE
| UNION
| ENUM
| ENUM_VALUE
| SCALAR
| INPUT_OBJECT
| INPUT_FIELD_DEFINITION
| ARGUMENT_DEFINITION
directive @tag(name: String!) repeatable on
| FIELD_DEFINITION
| INTERFACE
| OBJECT
| UNION
| ARGUMENT_DEFINITION
| SCALAR
| ENUM
| ENUM_VALUE
| INPUT_OBJECT
| INPUT_FIELD_DEFINITION
scalar FieldSet

#
# federation-v2.1
#

directive @composeDirective(name: String!) repeatable on SCHEMA

#
# https://specs.apollo.dev/link/v1.0/link-v1.0.graphql
#

directive @link(
url: String!,
as: String,
import: [Import])
repeatable on SCHEMA

scalar Import

#
# federation-v2.2
#

directive @shareable repeatable on FIELD_DEFINITION | OBJECT

#
# federation-v2.3
#

directive @interfaceObject on OBJECT
84 changes: 84 additions & 0 deletions ariadne/contrib/federation/definitions/fed_v2.5.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#
# https://specs.apollo.dev/federation/v2.0/federation-v2.0.graphql
#

directive @key(fields: FieldSet!, resolvable: Boolean = true) repeatable on OBJECT | INTERFACE
directive @requires(fields: FieldSet!) on FIELD_DEFINITION
directive @provides(fields: FieldSet!) on FIELD_DEFINITION
directive @external on OBJECT | FIELD_DEFINITION
directive @extends on OBJECT | INTERFACE
directive @override(from: String!) on FIELD_DEFINITION
directive @inaccessible on
| FIELD_DEFINITION
| OBJECT
| INTERFACE
| UNION
| ENUM
| ENUM_VALUE
| SCALAR
| INPUT_OBJECT
| INPUT_FIELD_DEFINITION
| ARGUMENT_DEFINITION
directive @tag(name: String!) repeatable on
| FIELD_DEFINITION
| INTERFACE
| OBJECT
| UNION
| ARGUMENT_DEFINITION
| SCALAR
| ENUM
| ENUM_VALUE
| INPUT_OBJECT
| INPUT_FIELD_DEFINITION
scalar FieldSet

#
# federation-v2.1
#

directive @composeDirective(name: String!) repeatable on SCHEMA

#
# https://specs.apollo.dev/link/v1.0/link-v1.0.graphql
#

directive @link(
url: String!,
as: String,
import: [Import])
repeatable on SCHEMA

scalar Import

#
# federation-v2.2
#

directive @shareable repeatable on FIELD_DEFINITION | OBJECT

#
# federation-v2.3
#

directive @interfaceObject on OBJECT

#
# federation-v2.5
#

directive @authenticated on
FIELD_DEFINITION
| OBJECT
| INTERFACE
| SCALAR
| ENUM

scalar federation__Scope

directive @requiresScopes(scopes: [[federation__Scope!]!]!) on
FIELD_DEFINITION
| OBJECT
| INTERFACE
| SCALAR
| ENUM

95 changes: 95 additions & 0 deletions ariadne/contrib/federation/definitions/fed_v2.6.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#
# https://specs.apollo.dev/federation/v2.0/federation-v2.0.graphql
#

directive @key(fields: FieldSet!, resolvable: Boolean = true) repeatable on OBJECT | INTERFACE
directive @requires(fields: FieldSet!) on FIELD_DEFINITION
directive @provides(fields: FieldSet!) on FIELD_DEFINITION
directive @external on OBJECT | FIELD_DEFINITION
directive @extends on OBJECT | INTERFACE
directive @override(from: String!) on FIELD_DEFINITION
directive @inaccessible on
| FIELD_DEFINITION
| OBJECT
| INTERFACE
| UNION
| ENUM
| ENUM_VALUE
| SCALAR
| INPUT_OBJECT
| INPUT_FIELD_DEFINITION
| ARGUMENT_DEFINITION
directive @tag(name: String!) repeatable on
| FIELD_DEFINITION
| INTERFACE
| OBJECT
| UNION
| ARGUMENT_DEFINITION
| SCALAR
| ENUM
| ENUM_VALUE
| INPUT_OBJECT
| INPUT_FIELD_DEFINITION
scalar FieldSet

#
# federation-v2.1
#

directive @composeDirective(name: String!) repeatable on SCHEMA

#
# https://specs.apollo.dev/link/v1.0/link-v1.0.graphql
#

directive @link(
url: String!,
as: String,
import: [Import])
repeatable on SCHEMA

scalar Import

#
# federation-v2.2
#

directive @shareable repeatable on FIELD_DEFINITION | OBJECT

#
# federation-v2.3
#

directive @interfaceObject on OBJECT

#
# federation-v2.5
#

directive @authenticated on
FIELD_DEFINITION
| OBJECT
| INTERFACE
| SCALAR
| ENUM

scalar federation__Scope

directive @requiresScopes(scopes: [[federation__Scope!]!]!) on
FIELD_DEFINITION
| OBJECT
| INTERFACE
| SCALAR
| ENUM

#
# federation-v2.5
#

scalar federation__Policy
directive @policy(policies: [[federation__Policy!]!]!) on
| FIELD_DEFINITION
| OBJECT
| INTERFACE
| SCALAR
| ENUM
34 changes: 18 additions & 16 deletions ariadne/contrib/federation/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,27 @@ def make_federated_schema(
r"(?<=@link).*?url:.*?\"(.*?)\".?[^)]+?", sdl, re.MULTILINE | re.DOTALL
) # use regex to parse if it's fed 1 or fed 2; adds dedicated typedefs per spec
dirname = os.path.dirname(__file__)
if link and link.group(1) == "https://specs.apollo.dev/federation/v2.0":
definitions = load_schema_from_path(
os.path.join(dirname, "./definitions/fed2_0.graphql")
)
elif link and link.group(1) == "https://specs.apollo.dev/federation/v2.1":
definitions = load_schema_from_path(
os.path.join(dirname, "./definitions/fed2_1.graphql")
)
elif link and link.group(1) == "https://specs.apollo.dev/federation/v2.2":
definitions = load_schema_from_path(
os.path.join(dirname, "./definitions/fed2_2.graphql")
)
elif link and link.group(1) == "https://specs.apollo.dev/federation/v2.3":
definitions = load_schema_from_path(
os.path.join(dirname, "./definitions/fed2_3.graphql")
definitions_folder = os.path.join(dirname, "definitions")
definition_files = os.listdir(definitions_folder)
definition_files.sort()
last_version_file = definition_files[-1]

if link:
# extract version
nogates marked this conversation as resolved.
Show resolved Hide resolved
fed_version = link.group(1).split("/")[-1]
nogates marked this conversation as resolved.
Show resolved Hide resolved
versioned_schema_file = os.path.join(
definitions_folder, f"fed_{fed_version}.graphql"
)

if os.path.isfile(versioned_schema_file):
definitions = load_schema_from_path(versioned_schema_file)
else:
definitions = load_schema_from_path(
os.path.join(definitions_folder, last_version_file)
)
else:
definitions = load_schema_from_path(
os.path.join(dirname, "./definitions/fed1_0.graphql")
os.path.join(dirname, "./definitions/fed_v1.0.graphql")
)

tdl.append(definitions)
Expand Down
3 changes: 3 additions & 0 deletions ariadne/contrib/federation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
"inaccessible", # Federation 2 directive.
"composeDirective", # Federation 2.1 directive.
"interfaceObject", # Federation 2.3 directive.
"authenticated", # Federation 2.5 directive.
"requiresScopes", # Federation 2.5 directive.
"policy", # Federation 2.6 directive.
]


Expand Down
Loading
Loading