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

Comments for GraphQL Union vs. Interface #522

Open
ashkan18 opened this issue Jan 15, 2019 · 9 comments
Open

Comments for GraphQL Union vs. Interface #522

ashkan18 opened this issue Jan 15, 2019 · 9 comments

Comments

@ashkan18
Copy link
Contributor

At Artsy we’ve been moving towards GraphQL for all of our new services. Acknowledging GraphLQ is a relatively new
technology, we faced some challenging questions as we were developing one our most recent services.

@alice-letourneur
Copy link

Hi, I've read your blog post and trying to implement something similar to the interface example you are sharing. I was wondering if you could share what the QueryType class looks like in the interface example as I'd like to understand what should be the type for the instruments field:

query {
  instruments {
    id
    name
    category
    ... on StringInstrument {
       numberOfStrings
    }
  }
}

@ashkan18
Copy link
Contributor Author

ashkan18 commented Jul 1, 2020

@alice-letourneur the type of instruments field should be InstrumentInterface. In an example here we define and OrderInterface which can be any of these types.
When want to expose a field with this type, we will use the interface type like this example. Let me know if you have any questions.

@alice-letourneur
Copy link

@alice-letourneur the type of instruments field should be InstrumentInterface. In an example here we define and OrderInterface which can be any of these types.
When want to expose a field with this type, we will use the interface type like this example. Let me know if you have any questions.

Thanks a lot for your answer, helped a lot, the issue I was having was actually the same as what you are describing at the end of the post, I just didn't realise it was:

One issue we found after doing the above was, since this way we don’t reference StringInstrument and DrumInstrument types anywhere in our schema, they actually don’t end up showing in the generated schema. For them to show up we have to add them as orphan_types in the interface.

Read more about it here: https://graphql-ruby.org/type_definitions/interfaces#orphan-types and all makes sense now.

@ashkan18
Copy link
Contributor Author

ashkan18 commented Jul 2, 2020

Oh yes! I remember that now! Yes, because these types are not directly accessed in our schema, they won't be included in the final schema unless we define them as Orphan Types. Happy that your problem is solved 😍

@kendallcarey
Copy link

The example links that were posted now show 404 errors. I am under the impression that the interfaces can define fields and the objects can inherit the fields keeping the code DRY. I am unable to query the fields on the objects implementing the interface. I was hoping to look at the examples as I wasn't able to find what I was looking for on graphql-ruby.org

@ashkan18
Copy link
Contributor Author

yes @kendallcarey , there are some examples here where price_field is defined on the interface and has a basic implementation.

Sorry about 404s, that repository this post is referring to is not public anymore 😞

@kendallcarey
Copy link

Thank you, I have been using that resource to create interfaces. I ended creating a stackoverflow question based on issues that I've been having: https://stackoverflow.com/questions/69715042/graphql-ruby-creating-interfaces-that-objects-can-inherit-fields-from

Am I misunderstanding interfaces?

@ashkan18
Copy link
Contributor Author

Replied to you on that thread.

@kendallcarey
Copy link

Thank you so much! I can't tell you how grateful I am for your help. I responded!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants