-
Notifications
You must be signed in to change notification settings - Fork 1.4k
node and nodes scalar type configuration #5381
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
Conversation
|
@rmosolgo I wanted to throw this proof of concept together quickly to get your thoughts 🙏 I'm open to any changes you suggest, or whatever you feel makes sense! |
|
Hmm after looking closer at this, maybe the configuration of the |
|
I'm open to accepting a customization here, but I don't want a global configuration object. Lots of applications run multiple schemas and I want to make sure that they can be configured separately. Here are a few other APIs I could imagine:
I'm definitely game to support something like this -- is there one of of those alternatives (or another non-global one) that you'd like to explore? |
|
I like Approach
will work so it won't be a breaking change. I'd still need to inject it here into the Do you have suggestions for that too? 🙏 |
|
@crpahl How many different variations of the ID scalar are we anticipating to be needed? I'm not familiar with the context around how this is effecting the path towards relay compliance, so maybe you could give me some quick context or point me towards some references. |
Hey @benzittlau, just one. For context, we use our own custom So that made me think of two options to work towards becoming Relay compliant:
|
|
I want to make sure I understand the context fully so am going to use this as an opportunity to do some digging into our current GraphQL implementation (in particular around ID handling). I'll come back once I have more understanding to make sure it aligns and we can go from there. While I'm doing that, you might be able to address one of the questions/concerns I have with the current implementation in your PR. Ruby meta programming is a "here be dragons" risk as it can be very hard to trace and debug (and for non-Ruby experts understand). The dynamic module approach in the PR is really nifty, but if there is a limited set of ID scalars we need, why not just explicit define them individually. Instead of: include GraphQL::Types::Relay::HasNodeField[id_type: IDTypeA]
include GraphQL::Types::Relay::HasNodeField[id_type: IDTypeB]Do: include GraphQL::Types::Relay::HasNodeFieldIDTypeA
include GraphQL::Types::Relay::HasNodeFieldIDTypeB |
|
Yeah that's fair @benzittlau! I think after syncing up on this, we'll go with your other suggestion for now and revisit something like my PR later if really needed. |
PR Description
This PR makes it possible to configure the
nodeandnodesscalar type through theConfigurationclass.For example, you could do this in a Rails initializer:
And the arguments to
nodeandnodeswould beid: SomeScalar!andids: [SomeScalar!]!respectively. The returnedidfield would beid: SomeScalar!.Why is this needed?
We don't use the GraphQL Ruby
IDscalar and instead use our own scalar for ID fields. Maybe we should consider going back to theIDscalar, but that's a different discussion/concern for if we ever want to go back in that direction 😄 This PR makes it possible to use our own scalar for the rootnodeandnodesfield.GraphQL Ruby doesn't support this type of configuration?
I ultimately need to be able to set the scalar type at Ruby load time. Here for example:
And setting this in a configuration class was the easiest way for me to do this through a simple Rails initializer. I realize this isn't a pattern that GraphQL Ruby takes for configuration (unless I missed it!) and I'm open to any other approaches!
Other approaches we considered
I realize I could also completely override the modules, but it felt much better to be able to configure/inject the type and save us from awkward monkey patching.