All of these use Stitch's arguments injection syntax.
@rest
fetches data from a REST/HTTP endpoint. Usage examples:
type Query {
allUsers: [User!] @rest(url: "http://user-service/users")
userById(userId: ID!): User @rest(url: "https://user-service/users/{args.userId}")
userById(userId: ID!): User
@rest(url: "https://old-user-service/getUser", query: [{ key: "id", value: "{args.userId}" }])
}
type Mutation {
createUser(body: UserInput!): User @rest(url: "https://user-service/users", method: "POST", bodyArg: "body")
}
Full parameters:
input KeyValue {
key: String!
value: String!
required: Boolean # Defaults to false
}
directive @rest(
url: String!
method: String # Defaults to GET
body: String
bodyArg: String # Defaults to "input"
query: [KeyValue!]
headers: [KeyValue!]
timeoutMs: Int # Defaults to 10 seconds
notFoundAsNull: Boolean # Defaults to isNullableType of field type
)
@gql
lets you "embed" a query on a remote GraphQL server into a Stitch resolver. It's not a full federation solution (coming soon!), but it let's you do most things you'd want to with a remote GraphQL endpoint.
Standard GraphQL subselections, aliases, variables, etc are all fully supported (relies on graphql-tools
's Remote Schemas)
Examples:
# Remote graphql server
type User {
id: ID!
name: String!
}
type Query {
getUsersNamed(name: String!): [User]
}
# Stitch
type Query {
allUsersNamedAviv: @gql(
url: "http://remote-user-service/graphql",
fieldName: "getUsersNamed",
arguments: {name: "aviv"})
getUsersByName(userName: String!): @gql(
url: "http://remote-user-service/graphql",
fieldName: "getUsersNamed",
arguments: {name: "{args.userName}"})
}
Full parameters:
enum GraphQLOperationType {
Query
Mutation
}
directive @gql(
url: String!
fieldName: String!
operationType: GraphQLOperationType
arguments: JSONObject
)
See Arguments Injection for details
@stub
lets you create a stub resolver, but make no mistake - this can be used with full parameter injection syntax to create complex resolvers. Examples:
type Query {
isAlive: Boolean @stub(value: true)
jsonEcho(input: JSON!): JSON @stub(value: { wrapper: "{args.input}" })
}
type User {
firstName: String!
lastName: String!
fullName: String! @stub(value: "{source.firstName} {source.lastName}")
}
Full parameters:
directive @stub(value: JSON!)