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

Extended Field DSL is not available within Function #980

Closed
RabidFire opened this issue Sep 22, 2017 · 1 comment
Closed

Extended Field DSL is not available within Function #980

RabidFire opened this issue Sep 22, 2017 · 1 comment

Comments

@RabidFire
Copy link

As written in the docs, a GraphQL::Function is a reusable container for field logic. However, extended Field DSL (specified using GraphQL::Field.accepts_definitions(...)) is not available within Functions.

Example

# Extend the Field DSL to accept :custom_metadata_key
GraphQL::Field.accepts_definitions(
  custom_metadata_key: GraphQL::Define.assign_metadata_key(:custom_metadata_key)
)
# This works
field :myField do
  custom_metadata_key 'test'
end
# This does not work
class MyFunction < GraphQL::Function
  custom_metadata_key: 'test'
end

field :myField, function: MyFunction.new

The problem is that GraphQL::Function is quite different from GraphQL::Field, GraphQL::ObjectType, etc, in that they are not defined (and therefore does not include the GraphQL::Define::InstanceDefinable module) and are instead subclassed.

Proposed Solutions

  1. (Workaround) Define a class method within the Function.
  2. Hook into Field.accepts_definitions to automatically define_singleton_method on GraphQL::Function.
  3. (Ideal) Wait for Object-oriented schema definition #820 - perhaps we won't need Functions if we can simply inherit from GraphQL::Field to define reusable fields.
@rmosolgo
Copy link
Owner

rmosolgo commented Aug 1, 2018

Function is out, Resolver is in, and Resolver should have all the API elements of normal class-based schema definition.

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

No branches or pull requests

2 participants