Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Support InlineFragments #62

Open
tberman opened this issue Jan 3, 2019 · 6 comments
Open

Support InlineFragments #62

tberman opened this issue Jan 3, 2019 · 6 comments
Assignees
Labels
feature request New feature request help wanted Extra attention is needed question Further information is requested

Comments

@tberman
Copy link

tberman commented Jan 3, 2019

Currently there doesn't appear to be a way to support inline fragments, I am looking to do something like:

query {
  someInterface {
    ... on SomeType {
      field
    }
  }
}

I may have missed how to do this, I tried decorating a field with @GraphQLProperty but it gave me back something that looked far more like a field alias than an Inline Fragment.

Thoughts?

If this is missing and there is consensus on how to do this, I'd be happy to put together a PR!

@chemdrew
Copy link
Contributor

Hi @tberman!

Currently this feature is not implemented.
The reason for this is that I couldn't figure out an intuitive way to do this and since inline fragments were a way to simplify queries by using some OOP concepts I figured the Nodes library provided the same user friendly behavior being implemented in OOP languages but at the cost of more complex queries being constructed under the hood.

My initial thoughts on how to solve this is adding an annotation that links to a Nodes compatible class that can be traversed to build the fragment query, used like this.

@GraphQLProperty(name = "someInterface")
@GraphQLFragment(fragment = Fragment.class, on = "SomeType")
class SomeInterface {
  private String someField;
  // getters + setters for someField...
}

I believe the implementation of this should not be too difficult, but have not looked into that yet. What are your thoughts on this? Would love to brainstorm on the best solution to this.

@chemdrew chemdrew self-assigned this Jan 20, 2019
@chemdrew chemdrew added help wanted Extra attention is needed question Further information is requested feature request New feature request labels Jan 20, 2019
@tberman
Copy link
Author

tberman commented Jan 20, 2019

Definitely happy to help sketch out an idea before working on it!

One thing before starting though, with unions and interfaces w/o inline fragment support you can't pull fields out that aren't on the base interface (and in the union case, they are unaccessible).

I think @GraphQLFragment would make sense. Why would you need the fragment = Fragment.class piece?

I guess I would think it wouldn't be too bad to have the data end up inside the fragment container, so something like:

class SomeInterface {
  @GraphQLFragment(on = "User")
  private User user;
  // getters + setters for user
}

class User {
  private String name;
  // getters + setters
}

And then when hydrating, we could put the data on user, so if you wanted name you would get it via:

anInstance.getUser().getName()

Thoughts?

@shivamsk
Copy link

@tberman @chemdrew
Can you guys please provide if there is any update on this to implement union ?

@tberman
Copy link
Author

tberman commented Apr 22, 2019

@shivamsk I am happy to work on a PR once we get to some kind of general agreement on how it should work API-wise!

@fefi42
Copy link

fefi42 commented Sep 9, 2019

Is there any work around to this at the moment?

@chandrantwins
Copy link

Hi , thanks for your library. do you have any update on this support?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature request New feature request help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants