Trying to solve, https://github.com/parse-community/parse-server/issues/7197

Hi,

I am trying to solve this bug, GraphQL error when retur.

We are in the process to migrate to gql but we still use a lot of cloud function and want to make the transition as simple as possible but this issue give us headache… I have seen that we use SchemaDirectiveVisitor to find the @resolve but it looks like we don’t use parseGraphQLSchema.addGraphQLQuery for when we add the queries, could that be the problem?

It looks that the array are being properly converted for the default queries but not when resolving results from cloud code functions.

I found that the result of the resolvers returns the same format ( standard query result). But I can’t find where the query result is actually parsed and transformed to a gql result. For the default query. I think defaultGraphQLTypes.loadArrayResult(this, parseClasses); has something to do with…

I have a test written for problem,

`it(‘can resolve a custom query, that returns an array’, async () => {
const schemaController = await parseServer.config.databaseController.loadSchema();

    await schemaController.addClassIfNotExists('SuperCar', {
      engine: { type: 'String' },
      doors: { type: 'Number' },
      price: { type: 'String' },
      mileage: { type: 'Number' },
      gears: { type: 'Array' }
    });

    await new Parse.Object('SuperCar').save({
      engine: 'petrol',
      doors: 3,
      price: '£7500',
      mileage: 0,
      gears: ['1', '2', '3', '4']
    });

    await new Parse.Object('SuperCar').save({
      engine: 'petrol',
      doors: 3,
      price: '£7500',
      mileage: 10000,
      gears: ['1', '2', '3', '4', '5']
    });

    await Promise.all([
      parseGraphQLServer.parseGraphQLController.cacheController.graphQL.clear(),
      parseGraphQLServer.parseGraphQLSchema.schemaCache.clear(),
    ]);

    Parse.Cloud.define('arrayOfSuperCar', async () => {
      const superCars = await new Parse.Query('SuperCar').find({useMasterKey: true})
      return superCars
    });
    const result = await apolloClient.query({
      query: gql`
      query FindSuperCar {
        arrayOfSuperCar {
          objectId
          objectId
          gears {
            ... on Element {
              value
            }
          }
        }
      }
    `,
    })
    expect(result.data.superCars.gears[2].value).toEqual('3');
  });`

Would you be interested in opening a PR with this failing test case and helping us to solve this issue?

I created a PR for which includes the test, inital test that shows the bug by axelhildingson · Pull Request #7506 · parse-community/parse-server · GitHub</titl

1 Like