Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mutations having @client fields are not returning server errors to the client. #7565

Open
cmnstmntmn opened this issue Jan 11, 2021 · 3 comments
Assignees
Labels
🔍 investigate Investigate further

Comments

@cmnstmntmn
Copy link

cmnstmntmn commented Jan 11, 2021

Hey, i think that the well known issue like this here related to the absence of server errors, is caused by the presence of the @client directive inside the mutation response.

ServerFieldOne
ServerFieldTwo
MyClientSideResolvedField @client

Removing @client fields, is fixing the issue.

@benjamn
Copy link
Member

benjamn commented Jan 11, 2021

@cmnstmntmn Just to make sure, you mean there's a server error for ServerFieldOne or ServerFieldTwo, but it's hidden when the MyClientSideResolvedField @client field is included in the mutation?

To implement the local field, are you using a local resolver function for that field (passing options.resolvers to the ApolloClient constructor), or a field policy read function, or something else?

@benjamn benjamn self-assigned this Jan 11, 2021
@cmnstmntmn
Copy link
Author

cmnstmntmn commented Jan 11, 2021

@benjamn no, the @client field computes two other fields. They are not included in the mutation (as input).
They're just part of the mutation response

mutation SaveTicket(
  $ID: Int
  $LocationID: Int!
  $Type: TicketType!
  $Status: TicketStatus!
  $Urgency: TicketUrgency!
  $PatientID: Int! = 0
) {
  SaveTicket(
    input: {
      ID: $ID
      LocationID: $LocationID
      Type: $Type
      Status: $Status
      Urgency: $Urgency
      PatientID: $PatientID
    }
  ) {
    ID
    Type
    Status
    Patient {
      ID
      FirstName
      LastName
      FullName @client
    }
  }
}

resolver

export const resolvers = {
  Patient: {
    FullName({FirstName, LastName}) {
      return `${FirstName} ${LastName}`;
    }
  },
}

The FullName resolver it's fine for queries; but it seems to be faulty with mutations.

As for resolvers, i'm passing them as options to the AplloClient constructor

const apolloClient = new ApolloClient({
  cache,
  connectToDevTools: false,
  typeDefs,
  resolvers,
  link,
});

@timukasr
Copy link

timukasr commented Sep 8, 2021

Having same issue. One field in mutation has @client directive. When server returns error, eg:
{"errors":[{"message":"Something went wrong, please try again"}],"data":null}
then this error is handled incorrectly by Apollo. It seems that it tries to read data.mutationField, and fails with error Cannot read property 'mutationField' of null at new ApolloError

@bignimbus bignimbus added the 🔍 investigate Investigate further label Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔍 investigate Investigate further
Projects
None yet
Development

No branches or pull requests

4 participants