graphql-engine-1.0.0: GraphQL API over Postgres
Safe HaskellSafe-Inferred
LanguageHaskell2010

Hasura.GraphQL.Execute.Remote

Synopsis

Documentation

resolveRemoteVariable :: MonadError QErr m => UserInfo -> RemoteSchemaVariable -> StateT RemoteJSONVariableMap m Variable Source #

Resolves a RemoteSchemaVariable into a GraphQL Variable.

A RemoteSchemaVariable can either be a query variable (i.e. a variable provided in the query) or it can be a SessionPresetVariable (in which case we look up the value of the session variable and coerce it into the appropriate type and then construct the GraphQL Variable).

NOTE: The session variable preset is a hard preset (i.e. if the session variable doesn't exist, an error will be thrown).

The name of the GraphQL variable generated will be a GraphQL-ized version of the session variable (i.e. - will be replaced with '_'), since session variables are not valid GraphQL names.

Additionally, we need to handle partially traversed JSON values; likewise, we create a new variable out of thin air.

For example, considering the following schema for a role:

input UserName { firstName : String! @preset(value:Foo) lastName : String! }

type Query { user( user_id: Int! @preset(value:"x-hasura-user-id") user_name: UserName! ): User }

and the incoming query to the graphql-engine is:

query($foo: UserName!) { user(user_name: $foo) { id name } }

with variables:

{ "foo": {"lastName": Bar} }

After resolving the session argument presets, the query that will be sent to the remote server will be:

query ($x_hasura_user_id: Int!, $hasura_json_var_1: String!) { user (user_id: $x_hasura_user_id, user_name: {firstName: Foo, lastName: $hasura_json_var_1}) { id name } }

runVariableCache :: Monad m => StateT RemoteJSONVariableMap m a -> m a Source #

TODO: Documentation.