parse-community / parse-community/parse-server

GraphQL error when returning array fields in cloud function

Open
#7,197 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type:bug
Dominant language
JavaScript
Stars
21.4k
Forks
4.8k
Avg merge
7h 45m
Merged PRs (30d)
11

Description

New Issue Checklist
Issue Description

Returning Parse Objects with array fields from a cloud function using GraphQL results in a runtime error.

In our example (simplified for clarity) we have added an array field roles to our Parse.User class. This has never been an issue with regular Parse queries or with autogenerated GraphQL queries.

Now we have been trying to add a cloud function search that returns an array of Parse.User, but we get following error when calling it with GraphQL:

"Abstract type "ArrayResult" must resolve to an Object type at runtime for field "User.roles". Either the "ArrayResult" type should provide a "resolveType" function or each possible type should provide an "isTypeOf" function."

Cloud function

async function search(request) {
  return new Parse.Query(Parse.User)
    .exists('roles')
    .find({ useMasterKey: true });
}

GraphQL schema

extend type Query {
  search(term: String!): [User] @resolve
}

GraphQL query

query userSearch {
  search(term: "test") {
    objectId
    username
    roles {
      ... on Element {
        value
      }
    }
  }
}

Example User object

{
  objectId: 'IeZkxfGtky'
  username: 'sana',
  roles: [ 'verified', 'moderator' ],
  // snip
}

Server

  • Parse Server version: 4.5.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the error with the shown search cloud function, schema, query, and Parse.User roles array on Parse Server 4.5.0. Trace how GraphQL resolves the User.roles ArrayResult field for objects returned by a cloud function. Done means the query returns array fields without the abstract-type runtime error.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, javascript
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.