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

Support for Inline Fragments #3

Closed
artonge opened this issue Aug 18, 2017 · 6 comments
Closed

Support for Inline Fragments #3

artonge opened this issue Aug 18, 2017 · 6 comments

Comments

@artonge
Copy link

artonge commented Aug 18, 2017

Hi,

Any plan to support Inline Fragments ?

Example :

query HeroForEpisode($ep: Episode!) {
  hero(episode: $ep) {
    name
    ... on Droid {  # <-- Inline Fragments
      primaryFunction
    }
  }
}

Do you think it would be feasible ?

Edit: manage to do without it. But it would be a nice feature :)

@dmitshur
Copy link
Member

dmitshur commented Aug 18, 2017

Yes, inline fragments are already supported. I still need to work on adding a section to README that explains how to do them. Let's use this issue to track that.

In the meantime, see issue shurcooL/githubv4#10 which was about union + inline fragment support. It was resolved in shurcooL/githubv4#15.

Edit: manage to do without it. But it would be a nice feature :)

Can you show you did it it? Then I can suggest a better way, if there is one.

@artonge
Copy link
Author

artonge commented Aug 19, 2017

Can you show you did it it? Then I can suggest a better way, if there is one.

I just found a way that don't need inline fragment in the API I use.

@dmitshur
Copy link
Member

I see. Here's how you can do the above GraphQL query using graphql syntax:

query HeroForEpisode($ep: Episode!) {
  hero(episode: $ep) {
    name
    ... on Droid {  # Inline Fragment.
      primaryFunction
    }
  }
}
var query struct {
	Hero struct {
		Name  graphql.String
		Droid struct {
			PrimaryFunction graphql.String
		} `graphql:"... on Droid"` // Inline Fragment.
	} `graphql:"hero(episode: $ep)"`
}

@dmitshur
Copy link
Member

@artonge, have you had a chance to try the above? Any issues?

@artonge
Copy link
Author

artonge commented Sep 6, 2017

Hi,
Sorry I was in holidays.
No I didn't tried it as I found an other way to do what I wanted.

@dmitshur
Copy link
Member

dmitshur commented Nov 3, 2017

The support for inline fragments is documented in README now:

https://github.com/shurcooL/graphql#inline-fragments

/cc @artonge FYI.

grihabor pushed a commit to grihabor/graphql that referenced this issue Nov 12, 2021
In the case we developers want to decode JSON response ourself. Moreover, the default `UnmarshalGraphQL` function isn't ideal with complicated nested interfaces
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants