Skip to content

Implement schema extend keyword #1

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

Closed
wants to merge 1 commit into from

Conversation

emilebosch
Copy link
Owner

@emilebosch emilebosch commented Jul 10, 2019

Approach to extending types such as https://graphql.github.io/graphql-spec/June2018/#sec-Type-Extensions

Todo

  • Implement brute force extension of types in the GraphQL::Schema::BuildFromDefinition so it actually extends types and "works".
  • Implement language printer vistors for printing back the document extend AST types to a string
  • Find a way to declaratively build a GraphQL::Schema with type extensions and come up with a pretty way to do this. Extensions don't have a description so we fall flat making a new object.from GraphQL::BaseType. If the wasn't a problem how would it look like then? See below for a proposal. Also extensions aren't connected to the schema, since they sort of come after the fact?
  • Make sure that we can convert from GraphQL::Schema back to GraphQL::Language::Document node. This mean tracking our extensions in some way or form so we can print it back. Check GraphQL::Language::DocumentFromSchemaDefinition and GraphQL::Schema::Printer
  • Refactor the code to make more readable
  • Tests maybe 🙈
  • Get Roberts blessing

Questions

  • How would we add type extensions to the API so that it gets generated properly?
  • Should when asking for .fields on an ObjectType should it return all the fields?

Proposal for extensions

Extensions come after the fact,i.e. they should extend an existing type. However I have no clue how to do this elegantly. It's not like an interface where it gets implemented.

Sample: 1 Pure after the fact thing

# The original type
UserType = GraphQL::ObjectType.define do
  field :name, String
end

# How do we hook it up in the schema? Like orphans maybe?
UserTypeExtension = GraphQL::ObjectTypeExtension.define do
  extends UserType #I don't know the order either, so this might create a circular ref exception
  field :email, String
end

# Maybe this?
Schema.extensios << UserTypeExtension

Another way is to implement it like an interface, but that's not really what it is.

How is the JS world tackling this

tldr;; They have an extendSchema that extends the schema

@emilebosch emilebosch force-pushed the implement-schema-extend-keyword branch from 5b793bd to 5449895 Compare July 10, 2019 17:29
@emilebosch emilebosch force-pushed the implement-schema-extend-keyword branch from c301f69 to c423f58 Compare August 31, 2021 11:49
@emilebosch emilebosch closed this Aug 3, 2023
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.

1 participant