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

Allow schema declaration directives #1176

Conversation

maartenvanvliet
Copy link
Contributor

In #1140 support was added for applying type system directives in the macro syntax, and in #1157 type extensions became possible in both SDL and macro syntax.

One omission in the above is directives on schema declarations, and applying type extensions on schema declarations. The omission prevents a full implementation of Apollo Federation 2.0 on top of Absinthe. This PR aims to improve on adding the support.

In Absinthe macro schema's it's not necessary to use schema declarations. This stays the same. However, when a type extension is applied to the schema declaration it's necessary for a pre-existing declaration. Therefore, the schema declaration is now inferred from the existing query/mutation/subscription objects. Only in the case of an SDL schema, there can be a pre-existing declaration.

The SDL rendering of blueprint schema's created an ad-hoc schema declaration if no declaration was available. This is no longer necessary.

a97a327 also fixes an issue where the description of the schema declaration was the description of the __schema object and not of the schema itself. The __absinthe_schema_declaration__ was added to help out here, and also expose the declaration after the schema is compiled.

The schema do ... end``` was added to the macro syntax, though it will only work in an extendblock. In a followup a toplevelschema do ... end` could also work.

This is necessary if we want to extend it. It also cleans up some
code that checks for the presence of a declaration.
This way it's easier to check for the presence of a declaration
when applying type extensions.
This is no longer necessary as every schema has a proper schema
declaration struct.
The filtering of the SchemaDeclaration is not necessary here
as this is already done in the ApplyDeclaration phase.
@@ -179,8 +183,7 @@ defmodule Absinthe.Schema.TypeSystemDirectiveTest do
end

@macro_schema_sdl """
"Represents a schema"
schema {
schema @feature(name: ":schema") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need extend? or for SDL is it support to declare this without extend?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out that SDL supports it without extend.

This is also covered by validation phases, and with this check the
extension of query/mutation/subscription objects is not possible.
@maartenvanvliet
Copy link
Contributor Author

For completeness I've also added support for macro based schema declaration. Also expanded support for extending builtin types such as query

@benwilson512 benwilson512 merged commit a276684 into absinthe-graphql:master Aug 9, 2022
@benwilson512
Copy link
Contributor

Fantastic, thanks!

@maartenvanvliet maartenvanvliet deleted the schema_declaration_directives branch August 11, 2022 18:11
maartenvanvliet added a commit to maartenvanvliet/absinthe that referenced this pull request Aug 26, 2022
Followup to absinthe-graphql#1176

Since every schema will have a declared or inferred declaration, this
can be used to mark root objects as referenced.

The MarkReferenced used to mark every :query/:subscription/:mutation object
as referenced, even when it was used in the declaration.

This fix ensures that root objects that are not used in the declaration
are not marked as referenced and thus not rendered in the SDL.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants