Support for returning GraphQLObjectType from resolveType was removed

56 Views Asked by At

After upgrading my application from Apollo v2 to v3, I encountered the following error:

Support for returning GraphQLObjectType from resolveType was removed in [email protected]. Please return type name instead.

This seems to be related to a change in [email protected]. I suspect that the issue might be related to how resolveType is handled in the schema.graphql or the resolver. I've checked the release notes for graphql-js and Apollo, but haven't found anything on this error

schema.graphql

union ModifiedResults =
    SuccessResult
  | NotFoundError
  | RequestsError

type SuccessResult {
  result: ScheduleRequest!
}

type MultipleSuccessResults {
  results: [ScheduleRequest!]!
}

type NotFoundError {
  message: String!
}

type RequestsError {
  message: String!
}

type ScheduleRequest {
  jobId: String!
  jobName: String!
  jobLabel: String
  status: Status!
  progress: Int!
  total: Int!
  result: [OperationResult!]!
  startedOn: String
  finishedOn: String
}

type Query {
    getModifiedResults(
    jobIds: [String!]!
  ): ModifiedResults
}

resolver where the request is made

getModifiedResults: async (
  _,
  { jobIds },
  { client: { clientId: headerClientId } },
) => {

  try {
    const results = prepareModifiedScheduleRequestsData(jobs, headerClientId);

    return {
      __typename: 'MultipleSuccessResults',
      results,
    };
  } catch (error) {
    if (error instanceof NotFoundError) {
      return {
        __typename: 'NotFoundError',
        message: error.reason,
      };
    } else if (error instanceof Error) {
      return {
        __typename: 'RequestsError',
        message: error.message,
      };
    }
    return {
      __typename: 'RequestsError',
      message: 'Unknown error',
    };
  }
},

Does anyone know if it's a possible to update the schema.graphql or the resolver to resolve this issue. Are there any changes in Apollo v3 that specifically address this breaking change in [email protected]?

Would really appreciate any hint on next steps to resolve this issue

0

There are 0 best solutions below