Graphcool / graphcool-framework

Apache License 2.0
1.78k stars 130 forks source link

Returning an error in test run not behaving properly #159

Open marktani opened 6 years ago

marktani commented 6 years ago

Issue by schickling Friday Sep 08, 2017 at 09:29 GMT Originally opened as https://github.com/graphcool/prisma/issues/397


Issue by wallslide Monday Jul 03, 2017 at 08:08 GMT Originally opened as https://github.com/graphcool/api-bugs/issues/160


What is the current behavior? When returning an object with the error property, two unexpected things happen:

  1. During a "Test run", no mention of the error is displayed.
  2. When performing a mutation against the Graphcool endpoint, instead of the string stored in the error property being returned in the request, instead the following is returned:
    [{"data":{"updateEvent":null},"errors":[{"message":"Whoops. Looks like an internal server error. Please contact us in Slack (https://slack.graph.cool) and send us your Request ID: cj4nuz43tv55u0116c70o78q0","requestId":"cj4nuz43tv55u0116c70o78q0","path":["updateEvent"],"locations":[{"line":2,"column":3}]}]}]

    Please share the relevant part of your GraphQL schema and all functions, permissions or other project settings for easier reproduction

Here is my RP function:

"use latest"
import moment from "moment";

export default function (event) {
  const {eventDurationMinutes, eventDateTime, status} = event.data;
  const shouldEndM = moment(eventDateTime).add(eventDurationMinutes, 'minutes');
  const shouldHaveEnded = moment().diff(shouldEndM) >= 0;
  if(status === "COMPLETED" && !shouldHaveEnded){
    return {error: "Cannot end event early"};
  }else{
    return {data: event.data};
  }
}

What is the expected behavior?

  1. I expect an error to appear in the test logs, instead of no response appearing.
  2. I expect the errors field in the http response to have the error that is returned in my RP function "Cannot end event early", instead of an internal server error message.
marktani commented 6 years ago

Comment by schickling Friday Sep 08, 2017 at 09:29 GMT


Comment by marktani Monday Jul 03, 2017 at 08:39 GMT


Can you share the relevant part of your GraphQL schema (the type the function is defined on) and the mutation that you run to trigger 2?

marktani commented 6 years ago

Comment by schickling Friday Sep 08, 2017 at 09:29 GMT


Comment by wallslide Monday Jul 03, 2017 at 08:45 GMT


type Event implements Node {
  ...
  eventDateTime: DateTime!
  eventDurationMinutes: Int!
  status: EVENT_STATUS! @defaultValue(value: RECRUITING_PARTICIPANTS)
  completedOn: DateTime
  ...
}
enum EVENT_STATUS {
  CANCELLED
  COMPLETED
  IN_PROGRESS
  RECRUITING_PARTICIPANTS
}
mutation EndEvent($eventId: ID!, $completedOn: DateTime! ){
        updateEvent(id: $eventId, status: COMPLETED, completedOn: $completedOn){
            id,
            status,
        }
    }

My function is meant to enforce the constraint "An event may not be set to COMPLETED before its expected end time, which is calculated by adding eventDurationMinutes to eventDateTime

marktani commented 6 years ago

Comment by schickling Friday Sep 08, 2017 at 09:29 GMT


Comment by marktani Monday Jul 03, 2017 at 08:46 GMT


I just looked into our logs, and 2. is an occurence of https://github.com/graphcool/api-bugs/issues/111, which will get fixed soon.

marktani commented 6 years ago

Comment by marktani Monday Sep 11, 2017 at 08:42 GMT


Hey @wallslide, 2. Should be fixed by now. Do errors still not show in test run for you? Might be related to #371