Arguments (GQL)
Use arguments to narrow searches and order results
In addition to pagination, you will often see where and orderBy arguments in queries. Here is an example summary of the apis query. The where argument is used to filter which APIs to return. The orderBy argument is used to order the results.
apis(
where: ApiWhereInput
orderBy: ApiOrderByInput
pagination: PaginationInput
): ApiConnection!
where arguments
The where argument for each query is usually of a type with a name ending in WhereInput. In the apis example above, the type name is ApiWhereInput.
type ApiWhereInput {
id: [ID!]
ownerId: [ID!]
subscriberId: [ID!]
visibility: ApiVisibility
apiSlugifiedName: [String!]
ownerSlugifiedName: [String!]
name: [String!]
isFavorite: Boolean
}
In this example, we query for the first 10 APIs owned by a user or team with an ID of 5713300.
query {
apis(
where: {
ownerId: 5713300
},
pagination: {
first: 10
},
) {
edges {
node {
id
name
}
}
pageInfo {
endCursor
hasNextPage
}
totalCount
}
}
orderBy arguments
The orderBy argument for each query is usually of a type with a name ending in OrderByInput. In the apis example above, the type name is ApiOrderByInput.
type ApiOrderByInput {
fields: [ApiSortingField!]
sortingFields: [ApiSortingField!]
}
The fields and sortingFields fields both expect a type named ApiSortingField. Either field can be used in your query.
type ApiSortingField {
fieldName: ApiSortingFieldName!
by: SortingFieldOrder!
}
If the fields or sortingFields field is included in the query, the fieldName must contain one of the values defined in the enum below. This is used to determine how the results are sorted. NAME is the default value.
enum ApiSortingFieldName {
NAME
VISIBILITY
CREATED_AT
UPDATED_AT
}
If the fields or sortingFields field is included in the query, the by field must contain one of the values defined in the enum below. This specifies whether the results are returned in ascending or descending order. ASC is the default value.
enum SortingFieldOrder {
ASC
DESC
}
In this query, we order the APIs by NAME in DESC order.
query {
apis(
where: { ownerId: 5713300 }
orderBy: { fields: { fieldName: NAME, by: DESC } }
pagination: { first: 60 }
) {
edges {
node {
id
name
}
}
pageInfo {
endCursor
hasNextPage
}
totalCount
}
}
Mutation (create, update, delete) arguments
Mutations involve creating, updating, and deleting information in the Enterprise Hub. Mutations usually include an argument of type ending in CreateInput, UpdateInput, or DeleteInput.
For example, the createApi mutation is shown below.
mutation createApi($apiCreateInput: ApiCreateInput!) {
createApi(api: $apiCreateInput) {
id
}
}
Notice that the createApi mutation expects an input of type ApiCreateInput.
type ApiCreateInput {
name: String!
title: String
pricing: ApiPricing
description: String!
category: String!
visibility: ApiVisibility
apiType: ApiType
version: NewApiVersionInput
}
The mutation can then be parameterized with variables:
{
"apiCreateInput": {
"name": "My RestApi",
"title": "My RestApi",
"category": "Other",
"description": "RestApi example",
"version": {
"name": "1.0"
}
}
}
Inputs with fields that have objects as values
If your input JSON has a field value that is an object inside of the object (such as
authentication
below), any existing object will be replaced with the object that you specify. For example, if your original input is this:{ "input": { "apiVersionId": "apiversion_57496a4a-9c45-4c79-9a8f-ae73b0fca1f5", "authentication": { "handleOauthTokenAtFrontend": false, "authorizationUrl": "<http://rapidapi.com>" } } }
and you want to set the
handleOauthTokenAtFrontend
value totrue
, you must also specify the existingauthorizationUrl
, because the entireauthentication
object will be replaced:{ "input": { "apiVersionId": "apiversion_57496a4a-9c45-4c79-9a8f-ae73b0fca1f5", "authentication": { "handleOauthTokenAtFrontend": true, "authorizationUrl": "<http://rapidapi.com>" } } }
If you do not set the
authorizationUrl
in the update, it will contain a blank value after the mutation is called.
Updated about 1 year ago