Skip to content

How to get outside input data into a query #32

Open
@stevan

Description

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

Metadata

Assignees

No one assigned

    Labels

    questionFurther information/thought is requested/required

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions