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

How to get outside input data into a query #32

Open
stevan opened this issue Oct 17, 2018 · 1 comment
Open

How to get outside input data into a query #32

stevan opened this issue Oct 17, 2018 · 1 comment
Labels
question Further information/thought is requested/required

Comments

@stevan
Copy link
Owner

stevan commented Oct 17, 2018

An in-house framework at work handles input from multiple sources using a very elegant resolver system design:

Some examples would be:

  • request:user.name
  • session:preferences.favorites.top10

The : separates the provider from the key-path that is used by the provider to resolve the value.

This could be handled with an extension to the directive system to allow it to be applied to variable definitions.

Example:

directive @default(from: String!) on VARIABLE_DEFINITION;

query SomeQuery (
        $user_id    : ID       @default(from: "request:user.id"),
        $top10_favs : [FavIDs] @default(from: "session:preferences.favorites.top10"),
    ) {

    user( id : $user_id ) {
        name
        birth  {
            date { year }
        }
        favs: favorites( ids: $top10_favs )
    }
}

The GraphQL execution system will be aware of the directive, and then will fetch all the values using the key (ex: "request:user.id").

They are just annotations, so by default they do nothing, which means they are easy to test

  • Simply pass in variable manually to override
  • Or provide a set of Mock providers

Related/Required

We need to add it to libgraphqlparser

I have a branch, but need to successfully test it

Supporting Links

An older RFC to add support for it
Now it is part of the current draft spec
And it is supported in the reference implementation

@stevan stevan added the question Further information/thought is requested/required label Oct 17, 2018
@stevan
Copy link
Owner Author

stevan commented Oct 29, 2018

Sent a PR and it passed CI :)

graphql/libgraphqlparser#75

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information/thought is requested/required
Projects
None yet
Development

No branches or pull requests

1 participant