Package graphql
Class GraphQLContext
java.lang.Object
graphql.GraphQLContext
This context object can be used to contain key values that can be useful as "context" when executing
DataFetcher
s
DataFetcher df = new DataFetcher() {
public Object get(DataFetchingEnvironment env) {
GraphQLContext ctx = env.getGraphqlContext()
User currentUser = ctx.getOrDefault("userKey",new AnonymousUser())
...
}
}
You can set this up via ExecutionInput.getGraphQLContext()
All keys and values in the context MUST be non null.
The class is mutable via a thread safe implementation but it is recommended to try to use this class in an immutable way if you can.-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionDeletes a key in the contextboolean
<T> T
Returns a value in the context by keystatic GraphQLContext
<T> T
getOrDefault
(Object key, T defaultValue) Returns a value in the context by key<T> Optional
<T> getOrEmpty
(Object key) Returns aOptional
value in the context by keyint
hashCode()
boolean
Returns true if the context contains a value for that keystatic GraphQLContext.Builder
Creates a new GraphqlContext builderstatic GraphQLContext
of
(Consumer<GraphQLContext.Builder> contextBuilderConsumer) Creates a new GraphqlContext with the map of context added to itstatic GraphQLContext
Creates a new GraphqlContext with the map of context added to itPuts a value into the contextputAll
(GraphQLContext context) Puts all of the values into the contextputAll
(GraphQLContext.Builder contextBuilder) Puts all of the values into the contextputAll
(Consumer<GraphQLContext.Builder> contextBuilderConsumer) Puts all of the values into the contextPuts all of the values into the contextstream()
toString()
-
Field Details
-
map
-
-
Constructor Details
-
GraphQLContext
-
-
Method Details
-
delete
Deletes a key in the context- Parameters:
key
- the key to delete- Returns:
- this GraphQLContext object
-
get
Returns a value in the context by key- Type Parameters:
T
- for two- Parameters:
key
- the key to look up- Returns:
- a value or null
-
getOrDefault
Returns a value in the context by key- Type Parameters:
T
- for two- Parameters:
key
- the key to look updefaultValue
- the default value to use if these is no key entry- Returns:
- a value or default value
-
getOrEmpty
Returns aOptional
value in the context by key- Type Parameters:
T
- for two- Parameters:
key
- the key to look up- Returns:
- a value or an empty optional value
-
hasKey
Returns true if the context contains a value for that key- Parameters:
key
- the key to lookup- Returns:
- true if there is a value for that key
-
put
Puts a value into the context- Parameters:
key
- the key to setvalue
- the new value (which not must be null)- Returns:
- this
GraphQLContext
object
-
putAll
Puts all of the values into the context- Parameters:
map
- the map of values to use- Returns:
- this
GraphQLContext
object
-
putAll
Puts all of the values into the context- Parameters:
context
- the other context to use- Returns:
- this
GraphQLContext
object
-
putAll
Puts all of the values into the context- Parameters:
contextBuilder
- the other context to use- Returns:
- this
GraphQLContext
object
-
putAll
Puts all of the values into the context- Parameters:
contextBuilderConsumer
- a call back to that gives out a builder to use- Returns:
- this
GraphQLContext
object
-
stream
- Returns:
- a stream of entries in the context
-
equals
-
hashCode
public int hashCode() -
toString
-
of
Creates a new GraphqlContext with the map of context added to it- Parameters:
mapOfContext
- the map of context value to use- Returns:
- the new GraphqlContext
-
of
Creates a new GraphqlContext with the map of context added to it- Parameters:
contextBuilderConsumer
- a callback that is given a new builder- Returns:
- the new GraphqlContext
-
getDefault
- Returns:
- a new and empty graphql context object
-
newContext
Creates a new GraphqlContext builder- Returns:
- the new builder
-