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

Introduce SourceSchemaDocument and FullSchemaDocument #1049

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

martinbonnin
Copy link
Contributor

Supersedes #1036

See also graphql/graphql-wg#1401 for the glossary.

This PR is a draft of what spec edits might look like to give a more precise idea of what it could end up like. Terminology and style to be fine tuned.

@netlify
Copy link

netlify bot commented Oct 4, 2023

Deploy Preview for graphql-spec-draft ready!

Name Link
🔨 Latest commit 00a3f3a
🔍 Latest deploy log https://app.netlify.com/sites/graphql-spec-draft/deploys/655b9d095875c7000853e5d6
😎 Deploy Preview https://deploy-preview-1049--graphql-spec-draft.netlify.app/draft
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

@mjmahone mjmahone left a comment

Choose a reason for hiding this comment

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

I am still a fan of this change

@@ -258,6 +260,8 @@ TypeSystemExtension :
- SchemaExtension
- TypeExtension

FullSchemaDocument : TypeSystemDefinition+
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting that we are disallowing extensions in the FullSchemaDocument. I'm not opposed but this is interesting.

That feels a little odd, as the Relay Compiler tends to overload extension to mean client-defined (this is probably wrong and we should switch to using a directive).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went with no extension by default to make a full schema as simple and as easy to read as possible.

A "full schema" is probably machine written and probably machine consumed as well. It's the source of truth for a service.

Another typical use case besides validation would be someone clicking their way in IntelliJ to find a type definition. I'd argue that having the extensions merged at that point would be nicer because you don't have to remember to "merge" things.

That being said, I think it'd be OK to "extend" a full schema:

client full schema = server full schema + type extensions

We'll probably end up encouraging this in Apollo Kotlin, possibly for stuff like @nullOnlyOnError

Comment on lines 355 to 356
built-in ones. Tools that are not implementations may use a {FullSchemaDocument}
to validate an operation.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure this singular purpose captures the depth of why FullSchemaDocument is useful. It's validation, but also code generation, IDE features, and more.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

💯 I'll reword


FullSchemaDocument : TypeSystemDefinition+

A {FullSchemaDocument} describes all the types in the schema, including the
Copy link
Contributor

Choose a reason for hiding this comment

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

"describes all the types in the schema" I'm not sure this is guaranteed to be true. It describes all the types that are visible to the consumer.

I know this is pedantic, but I'm currently using an equivalent of the "full schema document" in a way that says, for this library, what do we want to make available for codegen and validation, even if other types/fields exist and are exposed on the server.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair point 👍 . I guess it depends how much we want to bind this to introspection but I think it'd have some value having the FullSchemas be a super set of the introspection schema.

built-in ones. Tools that are not implementations may use a {FullSchemaDocument}
to validate an operation.

All _built-in definitions_ must be included in a {SourceSchemaDocument}.
Copy link
Contributor

Choose a reason for hiding this comment

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

FullSchemaDocument

Though I'm not sure this is true either. Any built-in definitions not included will be unavailable to tooling, and imply the schema is not spec compliant which is not the same as "must be included".

But for instance if there are no Float usages, does the full schema need to include the Float type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FullSchemaDocument

Indeed, thanks!

Though I'm not sure this is true either. Any built-in definitions not included will be unavailable to tooling, and imply the schema is not spec compliant which is not the same as "must be included".

Reason I went with this requirement is we're plagued with duplicate directive definitions. Latest example to date is apollographql/apollo-ios#3287. Right now, we've been adding directive definitions in order to validate documents but this really fragile to cases where the directive definitions do not match like this one.

if there are no Float usages, does the full schema need to include the Float type?

Good point. I guess it's not really required. The rule would then be "all used built-in definitions must be included", which is more flexible but also more prone to interpretation... But could be cool indeed.

spec/Section 2 -- Language.md Outdated Show resolved Hide resolved
spec/Section 3 -- Type System.md Outdated Show resolved Hide resolved
martinbonnin and others added 2 commits November 20, 2023 18:49
Co-authored-by: Matt Mahoney <mahoney.mattj@gmail.com>
Copy link
Contributor Author

@martinbonnin martinbonnin left a comment

Choose a reason for hiding this comment

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

Thanks for the review 💙

@@ -258,6 +260,8 @@ TypeSystemExtension :
- SchemaExtension
- TypeExtension

FullSchemaDocument : TypeSystemDefinition+
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went with no extension by default to make a full schema as simple and as easy to read as possible.

A "full schema" is probably machine written and probably machine consumed as well. It's the source of truth for a service.

Another typical use case besides validation would be someone clicking their way in IntelliJ to find a type definition. I'd argue that having the extensions merged at that point would be nicer because you don't have to remember to "merge" things.

That being said, I think it'd be OK to "extend" a full schema:

client full schema = server full schema + type extensions

We'll probably end up encouraging this in Apollo Kotlin, possibly for stuff like @nullOnlyOnError


FullSchemaDocument : TypeSystemDefinition+

A {FullSchemaDocument} describes all the types in the schema, including the
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair point 👍 . I guess it depends how much we want to bind this to introspection but I think it'd have some value having the FullSchemas be a super set of the introspection schema.

Comment on lines 355 to 356
built-in ones. Tools that are not implementations may use a {FullSchemaDocument}
to validate an operation.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

💯 I'll reword

built-in ones. Tools that are not implementations may use a {FullSchemaDocument}
to validate an operation.

All _built-in definitions_ must be included in a {SourceSchemaDocument}.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

FullSchemaDocument

Indeed, thanks!

Though I'm not sure this is true either. Any built-in definitions not included will be unavailable to tooling, and imply the schema is not spec compliant which is not the same as "must be included".

Reason I went with this requirement is we're plagued with duplicate directive definitions. Latest example to date is apollographql/apollo-ios#3287. Right now, we've been adding directive definitions in order to validate documents but this really fragile to cases where the directive definitions do not match like this one.

if there are no Float usages, does the full schema need to include the Float type?

Good point. I guess it's not really required. The rule would then be "all used built-in definitions must be included", which is more flexible but also more prone to interpretation... But could be cool indeed.

@benjie benjie added the 💭 Strawman (RFC 0) RFC Stage 0 (See CONTRIBUTING.md) label Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💭 Strawman (RFC 0) RFC Stage 0 (See CONTRIBUTING.md)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants