markhuot / craftql

A drop-in GraphQL server for Craft CMS
Other
320 stars 53 forks source link

Error "Uknown Type" on some entry types #302

Closed daltonrooney closed 5 years ago

daltonrooney commented 5 years ago

I'm running into a problem with a query that seems like it should work. The funny thing is that it does work in the CraftQL query editor in the CP. But when I run the same query from my app, I get an error.

Section: resources Entry types: report, course, policy, toolkit

Running this query on the backend successfully returns 3 entries:

query entries($limit: Int, $search: String, $relatedTo: [RelatedToInputType]) {
  entriesConnection(section: [resources], limit: $limit, search: $search, relatedTo: $relatedTo) {
    pageInfo {
      currentPage
      totalPages
    }
    entries {
      ... on ResourcesReport {
        title
        uri
        type {
          id
          handle
          name
        }
      }
      ... on ResourcesCourse {
        title
        uri
        type {
          id
          handle
          name
        }
      }
      ... on ResourcesPolicy {
        title
        uri
        type {
          id
          handle
          name
        }
      }
      ... on ResourcesToolkit {
        title
        uri
        type {
          id
          handle
          name
        }
      }
    }
  }
}

Here's the data that's returned:

{
  "data": {
    "entriesConnection": {
      "pageInfo": {
        "currentPage": 1,
        "totalPages": 1
      },
      "entries": [
        {
          "title": "Resource One (Course)",
          "uri": "resources/resource-one",
          "type": {
            "id": 2,
            "handle": "course",
            "name": "Course"
          }
        },
        {
          "title": "Resource Two",
          "uri": "resources/resource-two",
          "type": {
            "id": 1,
            "handle": "report",
            "name": "Report"
          }
        },
        {
          "title": "Resource Three",
          "uri": "resources/resource-3",
          "type": {
            "id": 1,
            "handle": "report",
            "name": "Report"
          }
        }
      ]
    }
  }
}

But when queried from the front end, I get this:

{
  "response": {
    "errors": [
      {
        "message": "Unknown type \"ResourcesCourse\".",
        "category": "graphql",
        "locations": [
          {
            "line": 18,
            "column": 14
          }
        ]
      },
      {
        "message": "Unknown type \"ResourcesPolicy\".",
        "category": "graphql",
        "locations": [
          {
            "line": 27,
            "column": 14
          }
        ]
      },
      {
        "message": "Unknown type \"ResourcesToolkit\".",
        "category": "graphql",
        "locations": [
          {
            "line": 36,
            "column": 14
          }
        ]
      }
    ],
    "status": 200
  }
}

Any thoughts?

daltonrooney commented 5 years ago

Solved. I didn't realize you needed to approve new entry types in the token settings before they are available in the API.