Skip to content

Latest commit

 

History

History
263 lines (229 loc) · 7.43 KB

querying-entries.md

File metadata and controls

263 lines (229 loc) · 7.43 KB

Querying Entries & Draft Entries

Gravity Forms Entries are registed to the GraphQL schema as the GfEntry interface, with the individual entry types as objects that implement that interface.

The following Gravity Forms entry types are supported:

  • SubmittedEntry: These are Gravity Forms Entries submitted by the user. They can be queried individually or as a list.
  • DraftEntry: These are Gravity Forms Draft Entries, generated by the Save and Continue link. They can be queried individually by their assigned resume_token.
  • PartialEntry: Not currently supported.

Get a single entry

Gravity Forms entry objects can be queried directly with gfSubmittedEntry , or as part of the gfEntry interface. The example query below shows how you can get a single entry by ID, and data about the fields and their values.

The id input accepts either the Gravity Forms Entry ID ( idType: DATABASE_ID ), or a global ID ( idType: ID ).

Example Query

{
  gfEntry(id: 2977, idType: DATABASE_ID) {
    id # global ID
    formDatabaseId
    isDraft
    formFields(first: 300) {
      nodes {
        databaseId
        type
        ... on TextField {
          label
          value # The field value
        }
      }
    }
    ... on SubmittedEntry {
      databaseId
      isStarred
    }
  }

  # is the same as:
  gfSubmittedEntry(id: 2977, idType: DATABASE_ID ){
    databaseId
    id # global ID
    formDatabaseId
    isDraft
    isStarred
    formFields(first: 300) {
      nodes {
        databaseId
        type
        ... on TextField {
          label
          value # The field value
        }
      }
    }
  }
}

Order Summaries

Entries that include Pricing Fields can return a GfOrderSummary object, which provides summarized order data from the entire entry.

Example Query

{
  gfEntry(id: 2977, idType: DATABASE_ID) {
    id # global ID
    formDatabaseId
    isDraft
    orderSummary {
      currency
      items {
        connectedFormField {
          ... on ProductSingleField {
            databaseId
          }
        }
        currency
        description
        isDiscount
        isLineItem
        isRecurring
        isSetupFee
        isShipping
        isTrial
        name
        price
        options {
          connectedFormField {
            ... on OptionCheckboxField {
              databaseId
            }
          }
          fieldLabel
          name
          optionLabel
          price
        }
        quantity
        section
        subtotal
        
      }
      subtotal
      total
    }
    ... on SubmittedEntry {
      databaseId
    }
  }
}

Quiz Results

Submitted entries that include a Quiz Field can return an EntryQuizResults object, which provides the summarized quiz data for the entire form.

Example Query

{
  gfSubmittedEntry(id: 2977, idType: DATABASE_ID ){
    databaseId
    quizResults {
      grade
      isPassingScore
      percent
      score
    }
  }
}

Get a Single Draft Entry

Draft entries can be queried directly with gfDraftEntry or as part of gfEntry . The query is similar to querying SubmittedEntry objects.

To query a Draft Entry, you simply use its resumeToken instead of the database Id.

Example Query

{
  gfEntry( id: "f82a5d986f4d4f199893f751adee98e9", idType: 'RESUME_TOKEN' ){
    ... on GfDraftEntry {
      resumeToken # f82a5d986f4d4f199893f751adee98e9
    }
  }
  # is the same as:
  gfDraftEntry( id: "f82a5d986f4d4f199893f751adee98e9", idType: 'RESUME_TOKEN' ){
    resumeToken # f82a5d986f4d4f199893f751adee98e9
  }
}

Get a List of Entries

The code comments in the example query below shows how you can fetch and filter data for multiple entries at once.

Cursor-based pagination is supported. You can use the first , last , before and after fields, along with the data inside of pageInfo and the cursors returned by the API to get each page of forms data.

By default, WPGraphQL sets the maximum query amount to 100. This can be overridden using the graphql_connection_max_query_amount filter.

Note

Currently, only lists of Submitted Entries are supported. Future versions will add support for querying lists of Draft and Partial entries.

{
  gfEntries(
    first: 20
    after: "YXJyYXljb25uZWN0aW9uOjk=" # Or pass null to start from the beginning.
    where: {
      # List of all the form IDs to include.
      formIds: [1]
      # Find entries between this start & end date.
      dateFilters: {
        startDate: "2019-09-22 02:26:23"
        endDate: "2019-10-25 02:26:23"
      }
      entryType: 'SUBMITTED' # Other entry types are not currently supported.
      fieldFiltersMode: ALL
      fieldFilters: [
        # Return specific list of entries.
        { key: "id", intValues: [5, 27, 350] }
        # Find entries created by user ID 1.
        { key: "created_by", intValues: [1], operator: IN }
        # Find entries where field 5 has a value of "somevalue".
        { key: "5", stringValues: [ "somevalue" ], operator: IN }
        # Search all entry meta fields for a value.
        { stringValues: "somevalue", operator: CONTAINS }
      ]
      # Sort fields in ascending order by "date_created"
      orderby: { order: ASC, isNumeric: false, field: "date_created" }
      # Show only active entries.
      status: ACTIVE
    }
  ) {
    pageInfo {
      startCursor
      endCursor
      hasPreviousPage
      hasNextPage
    }
    nodes {
      formDatabaseId
      isDraft
      formFields(first: 300) {
        nodes {
          ... on TextField {
            value
          }
        }
      }
      ... on GfSubmittedEntry{
        databaseId
        status
      }
    }
  }
  # is the same as
  gfSubmittedEntries(
    first: 20
    after: "YXJyYXljb25uZWN0aW9uOjk=" # Or pass null to start from the beginning.
    where: $whereArgs
  ){
    pageInfo {
      startCursor
      endCursor
      hasPreviousPage
      hasNextPage
    }
    nodes {
      databaseId
      formDatabaseId
      isDraft
      formFields(first: 300) {
        nodes {
          ... on TextField {
            value
          }
        }
      }
      status
    }
  }
}

Get a List of Draft Entries

Coming soon 🤫

Access Permissions

This plugin respects Gravity Forms default access permissions.

That means by default logged-in users may access their own individual submitted entries, while users with either the gravityforms_view_entries or gform_full_access capabilities can view others submitted entries and query for lists of entries.

By default, Gravity Forms does not limit permissions for accessing draft entries, as an entry-specific resumeToken is used to provide access.

To change the access permissions for submitted and draft entries, you can use the [graphql_gf_can_view_entries]((actions-and-filters.md#graphql_gf_can_view_entries) and graphql_gf_can_view_draft_entries filters, respectively.