Skip to content

Ideas for namespacing in schema #175

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
bmcdaniel11 opened this issue Jul 6, 2016 · 7 comments
Closed

Ideas for namespacing in schema #175

bmcdaniel11 opened this issue Jul 6, 2016 · 7 comments

Comments

@bmcdaniel11
Copy link

We run our integration of graphql out of a ruby engine, so the majority of our models are namespaced. We would like to continue the namespace pattern with queries/mutations but are finding it difficult.

For example, we have a model Person namespaced under engine Engine and would like to have the schema for the query type to match, ie name 'Engine::Person'. While the schema supports this syntax, any graphql request breaks when trying to pull a fragment to match the name. We have thought of multiple hacks to get around the issue, but were wondering if anyone had any ideas on how we could accomplish this cleanly. I added a bit of code below to illustrate the issue.

person.rb

module Engine
  class Person
    ...
  end 
end

person_type.rb

PersonType = GraphQL::ObjectType.define do 
  name 'Engine::Person'
  ...
end

graphql request

fragment on Engine::Person {
  name
  ...
}

This sets up the problem, as the fragment request breaks since it does not allow '::' in the syntax. We would like a clean way to have our schema represent our actual model structure and be able to query it as well. Any ideas would be great!

@rmosolgo
Copy link
Owner

rmosolgo commented Jul 6, 2016

I'm interested in sticking to the spec, which describes names as /[_A-Za-z][_0-9A-Za-z]*/. So you could:

@rmosolgo
Copy link
Owner

rmosolgo commented Jul 6, 2016

Makes me think, maybe graphql-ruby should assert than any ObjectType's name matches the required pattern!

@bmcdaniel11
Copy link
Author

I'm definitely in agreement with sticking to the spec, and I was actually surprised I was able to get it named with the "::" in the schema, so an assertion there would probably be useful. My thoughts were around modifying the GraphQLObjectType definition to be able to include an additional field allowing us to do a full class name. I think this was being discussed on the slack channel, I'll hop in there to continue discussion and close this when we reach a resolution.

@rosskevin
Copy link

I've got the indexing of class names implemented (patterned after/reused the ReduceTypes), I just need to hook it into the BaseType resolver and test it out tomorrow. I should be able to PR it in the morning.

https://github.com/rosskevin/graphql-ruby/tree/namespaced-model-support

@rosskevin
Copy link

PR #176 submitted passes tests and is verified working in the live environment. Usage for object_from_id detailed in readme PR https://github.com/rmosolgo/graphql-relay-ruby/pull/56

@bmcdaniel11
Copy link
Author

The solution given in issue #176 solves this problem. Closing issue.

@emilebosch
Copy link
Contributor

@bmcdaniel11 I'm looking for people that have experience wrapping Graphql In rails engines. can u contact me on [email protected]? thanks much!

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

4 participants