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

[IDL] Support accepts_definitions functions in IDL #789

Closed
wants to merge 3 commits into from

Conversation

rmosolgo
Copy link
Owner

@rmosolgo rmosolgo commented Jun 17, 2017

In the DSL, the best way to customize parts of a GraphQL schema is with custom definitions.

It would be nice to have a similar feature for the IDL, why not use the same feature?

Shout out to @theorygeek for first suggesting the parse -> apply -> remove pipeline for extracting behavior from IDL descriptions.

See to-dos and caveats below.

On this branch, these are equivalent:

Field

DSL

field :thing,  types.String, "A thing", property: :other_thing, authorize: :admin

IDL

# A thing 
# @property :other_thing
# @authorize :admin 
thing: String

Type

DSL

Types::ThingType = GraphQL::ObjectType.define do 
  name "Thing" 
  description "A thing"
  access :viewer
  # ...
end 

IDL

# A thing 
# @access :viewer
type Thing {
  # ...
}

Schema

DSL

MySchema = GraphQL::Schema.define do 
  max_complexity 1000
  object_from_id Helpers::ObjectFromId
  use GraphQL::Batch
end 

IDL

# @max_complexity 1000 
# @object_from_id Helpers::ObjectFromId
# @use GraphQL::Batch
schema {
  query Query 
}

Caveats

  • Input is passed to instance_eval which is unsafe. This is ok for safe input, but it's a foot-gun if turn user input into a schema. I should lock down the parser a bit.
  • TODO: lossless schema dump (ie, .to_definition should include @-definitions)
  • TODO: somehow give a context-aware backtrace if something fails.
  • TODO: support all customizable objects (eg GraphQL::Argument for prepare: handlers)
  • TODO: don't reuse instrument -- find a new name for this
  • TODO: don't use @, since it's already used for directives?

@rmosolgo rmosolgo mentioned this pull request Jun 19, 2017
@ThisIsMissEm
Copy link
Contributor

Supporting declarations through IDL would be very nice!

@rmosolgo
Copy link
Owner Author

rmosolgo commented Aug 7, 2017

I really like this approach, but I'm going to put it on the backburner and try #871 first.

@rmosolgo rmosolgo closed this Aug 7, 2017
@rmosolgo rmosolgo deleted the idl-instrumentation branch January 26, 2018 13:31
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.

2 participants