5. Connection Type

3.5 Connection Type

Error Explanation: Field SomeField Doesn't Exist on Type SomeType

The error message indicates that the field SomeField does not exist on the type SomeType. This often happens when SomeType is a connection type used for pagination, rather than a straightforward object type.

Step 1. Search for all types and look for "Connection" which is a common naming convention for connection types, and search for ones with edges and nodes

{
  __schema {
    types {
      name
    }
  }
}

Step 2. Search for specific type.

{
  __type(name: "UserCoreConnection") {
    name
    fields {
      name
      type {
        name
        kind
      }
    }
  }
}

Example result. Notice edges and pageinfo.

{
  "data": {
    "__type": {
      "name": "UserCoreConnection",
      "fields": [
        {
          "name": "edges",
          "type": {
            "name": null,
            "kind": "LIST"
          }
        },
        {
          "name": "pageInfo",
          "type": {
            "name": "PageInfo",
            "kind": "OBJECT"
          }
        }
      ]
    }
  }
}

Connection Types in GraphQL

Connection types are used to handle lists of items with pagination. Instead of directly returning a list of objects, a connection type typically includes:

Example of a Connection Type Structure

type UserCoreConnection {
  edges: [UserCoreEdge]
  pageInfo: PageInfo
}

type UserCoreEdge {
  node: UserCore
  cursor: String
}

type PageInfo {
  endCursor: String
  hasNextPage: Boolean
}

type UserCore {
  id: ID!
  name: String
  email: String
}

Accessing Fields within a Connection

To access fields like id, name, and email from the UserCore type within a connection, you need to drill down from edges to node:

{
  users {
    edges {
      node {
        id
        name
        email
      }
    }
    pageInfo {
      endCursor
      hasNextPage
    }
  }
}

Explanation: