Both forms and entries use the formFields
GraphQL Interface to retrieve information about Gravity Forms fields, and their submission values.
In addition to the shared fields available on the Interface, each Gravity Forms Field type has its own set of GraphQL fields that are accessible with query fragments.
As of v0.10.0, all Gravity Forms Fields - including custom ones - are automatically registered to the GraphQL schema - included custom ones!, and their specific GraphQL fields generated from GF_Field::get_form_editor_field_settings()
. If you are using custom editor field settings, you will need to register those manually.
{
gfForm(id: 1, idType: DATABASE_ID) {
formDatabaseId
formFields(first: 300) {
nodes {
id
type
cssClass
... on TextField {
description
label
isRequired
}
... on CheckboxField {
description
label
choices {
isSelected
text
value
}
}
... on NameField {
description
label
inputs {
isHidden
label
placeholder
}
}
}
}
}
}
Entry values can be accessed similarly to other Gravity Forms Field properties, by including the corresonding GraphQL field in the fragment.
Note: Due to GraphQL limitations regarding Union types, you must use the specific value type specific to that field. A full list of field value types and their corresponding field fragments are below.
As of v0.10.0, all formFields
have access to the value
GraphQL field, which provides the string representation of the entry value, created by GF_Field::get_value_export()
. Certain supported formFields
provide a value type specific to that field, as follows:
Field Value Type | Used by | Available subfields |
---|---|---|
addressValues ( obj ) |
AddressField |
city country lineTwo state street zip |
checkboxValues ( [ obj ] ) |
CheckboxField |
inputId text value |
fileUploadValues ( [ obj ] ) |
FileUploadField |
basePath baseUrl filename url |
imageValues ( obj ) |
ImageField |
altText basePath baseUrl caption description filename title url |
listValues ( [ obj ] ) |
ListField |
values ( [ string ] ) |
nameValues ( obj ) |
NameField |
first last middle prefix suffix |
timeValues ( obj ) |
TimeField |
amPm displayValue hours minutes |
values ( [ string] ) |
ChainedSelectField MultiSelectField PostCategoryField PostTagsField QuizField |
n/a |
{
gfEntry(id: 1, idType: DATABASE_ID) {
databaseId
formFields(first: 300) {
nodes {
... on CheckboxField {
checkboxValues {
inputId
value
}
}
... on NameField {
nameValues {
prefix
first
middle
last
suffix
}
}
... on TextField {
value
}
}
}
}
}
The code comments in the example query below explain how you can get a filtered list of form fields.
{
gfEntry(id: 1, idType: DATABASE_ID) {
databaseId
formFields(
first: 300
after: "YXJyYXljb25uZWN0aW9uOjI=" # Or pass null to start from the beginning.
where: {
# Return a specific list of form fields.
ids: [1,4,8]
# Find form fields by their `adminLabel`.
adminLabels: ['projectID', 'mylabel']
# Filter form fields by field types.
fieldTypes: [ ADDRESS, MULTISELECT, TEXTAREA ]
# Filter form fields by the page number in multi-page forms.
pageNumber: 2
}
) {
nodes {
id
type
}
}
}