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

Help: example with directives #38

Open
MShoaei opened this issue Mar 28, 2019 · 2 comments
Open

Help: example with directives #38

MShoaei opened this issue Mar 28, 2019 · 2 comments
Labels

Comments

@MShoaei
Copy link

MShoaei commented Mar 28, 2019

Can someone please provide a query example which uses @skip or @include directive?

@MShoaei MShoaei changed the title Help: emaple with directives Help: example with directives Mar 28, 2019
@dmitshur
Copy link
Member

It's not a small example, but the @include directive is used here.

@MShoaei
Copy link
Author

MShoaei commented Mar 29, 2019

@dmitshur Thank you for your reply.
so here is how i got it to work:
using this schema

type Test {
    field1 String!
    field2 String!
}

type Query{
    tests: [Test!]!
}

the struct I used is:

var q struct {
    Test []struct {
        Field1 graphql.string 
        IncludeField1 graphql.string `graphql:"@include(if:$f1)"`
        Field2 graphql.string
        IncludeField2 graphql.string `graphql:"@include(if:$f2)"`
    }
}

v := map[string]interface{
    "f1": graphql.Boolean(true),
    "f2": graphql.Boolean(false),
}
client.Query(context.Background(), &q, v)

I would really appreciate a better solution.

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

No branches or pull requests

2 participants