Package io.smallrye.graphql.api
Interface Context
-
@Experimental("Request context to allow downstream operations to get insight into the request. Not covered by the specification. Subject to change.") public interface Context
Holing context for the current request There are two parts to this.The initial request, that can be a aggregation of requests, and the current execution context.- Author:
- Phillip Kruger ([email protected])
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
Context.VariablesParser
Help to parse the variables
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default <A> A
getArgument(String name)
Get the argument using a name This return the argument instance if it existsdefault <A> A
getArgumentOrDefault(String name, A defaultValue)
Same as above but with the option to do a default value<A> Map<String,A>
getArguments()
Get all the argumentsString
getExecutionId()
Get the execution ID.String
getFieldName()
Get the field nameOptional<String>
getOperationName()
Get the operationName of the request.String
getOperationType()
Return the current type (Query, Mutation ext) Current type means the type currently being executed.Optional<String>
getParentTypeName()
Return the type name of the parent (if any)String
getPath()
Return the current pathdefault String
getQuery()
Get the query part of the request.javax.json.JsonObject
getRequest()
Get the full body of the request.List<String>
getRequestedOperationTypes()
Return all the operation types requested (unique list) A Request can contain more than one operation.javax.json.JsonArray
getSelectedAndSourceFields()
Return the fields and source fields in the requestjavax.json.JsonArray
getSelectedFields()
Return the fields selected in the request<S> S
getSource()
default Optional<Map<String,Object>>
getVariables()
Get the variables of the request Could be null (not set)default <A> Boolean
hasArgument(String name)
Return true if the argument existdefault boolean
hasOperationName()
Check if the request contains an operation namedefault boolean
hasRequest()
Check if there is a request setdefault boolean
hasSource()
default boolean
hasVariables()
Check if the request contains variables<T> T
unwrap(Class<T> wrappedType)
This leaky abstraction allows falling down to the underlying implementation
-
-
-
Field Detail
-
QUERY
static final String QUERY
- See Also:
- Constant Field Values
-
OPERATION_NAME
static final String OPERATION_NAME
- See Also:
- Constant Field Values
-
VARIABLES
static final String VARIABLES
- See Also:
- Constant Field Values
-
-
Method Detail
-
getRequest
javax.json.JsonObject getRequest()
Get the full body of the request. This includes the query, variables and operation name- Returns:
- JsonObject
-
hasRequest
default boolean hasRequest()
Check if there is a request set- Returns:
-
getQuery
default String getQuery()
Get the query part of the request. TODO: Consider creating a domain object for this (rather than String).- Returns:
- raw string query
-
getOperationName
Optional<String> getOperationName()
Get the operationName of the request. Could be null (not set)- Returns:
- the operation name if set
-
hasOperationName
default boolean hasOperationName()
Check if the request contains an operation name- Returns:
- true if it does
-
getVariables
default Optional<Map<String,Object>> getVariables()
Get the variables of the request Could be null (not set)- Returns:
-
hasVariables
default boolean hasVariables()
Check if the request contains variables- Returns:
- true if it does
-
getExecutionId
String getExecutionId()
Get the execution ID.- Returns:
- the ID as a String
-
getFieldName
String getFieldName()
Get the field name- Returns:
- name of the field
-
hasArgument
default <A> Boolean hasArgument(String name)
Return true if the argument exist- Parameters:
name
- the argument name- Returns:
- true if there
-
getArgument
default <A> A getArgument(String name)
Get the argument using a name This return the argument instance if it exists- Parameters:
name
- key- Returns:
- argument value
-
getArgumentOrDefault
default <A> A getArgumentOrDefault(String name, A defaultValue)
Same as above but with the option to do a default value- Parameters:
name
-defaultValue
-- Returns:
- the argument instance if it exists, else the provided default
-
getArguments
<A> Map<String,A> getArguments()
Get all the arguments- Returns:
- a map with name and instance of the argument
-
hasSource
default boolean hasSource()
-
getSource
<S> S getSource()
-
getPath
String getPath()
Return the current path- Returns:
- the path as a String
-
getSelectedFields
javax.json.JsonArray getSelectedFields()
Return the fields selected in the request- Returns:
- JsonArray of fields selected
-
getSelectedAndSourceFields
javax.json.JsonArray getSelectedAndSourceFields()
Return the fields and source fields in the request- Returns:
- JsonArray of fields selected
-
getOperationType
String getOperationType()
Return the current type (Query, Mutation ext) Current type means the type currently being executed.- Returns:
- name of the operation type
-
getRequestedOperationTypes
List<String> getRequestedOperationTypes()
Return all the operation types requested (unique list) A Request can contain more than one operation. This will return a unique list of types. So if there is 2 Queries, it will only return one QUERY type, but if there is two queries and a mutation, it will return QUERY,MUTATION- Returns:
-
getParentTypeName
Optional<String> getParentTypeName()
Return the type name of the parent (if any)- Returns:
- the parent type name maybe
-
unwrap
<T> T unwrap(Class<T> wrappedType)
This leaky abstraction allows falling down to the underlying implementation- Type Parameters:
T
- the implementation class- Parameters:
wrappedType
- the class type of T- Returns:
- instance of the implementation class
-
-