excitement-engineer / graphql-iso-date

A set of RFC 3339 compliant date/time GraphQL scalar types.
MIT License
523 stars 50 forks source link

GraphQLDate inputs cannot be delegated #106

Open MarkPolivchuk opened 5 years ago

MarkPolivchuk commented 5 years ago

If Service A has a mutation accepting a GraphQLDate input and it needs to delegate or forward that to another Service B with the same signature, the GraphQLDate yyyy-mm-dd string will be converted to a full DateTime string yyyy-mm-ddT00:00:00Z before arriving at Service B which fails validation.

For example, if the same mutation exists both in Service A and Service B, with A delegating the mutation to Service B:

Mutation {
  updateUser(input: UserInput!): User!
}

type User {
  id: ID!
  dob: GraphQLDate!
}

input UserInput {
  id: ID!
  dob: GraphQLDate!
}

And a client mutates Service A with the following

mutation updateUser($input: UserInput) {
  updateUser(input: $input) {
    id
    dob
  }
}

{
  "input": {
    "id": "1234",
    "dob": "2000-01-01"
  }
}

When service B receives the mutation, it will see the following as the input because it is being parsed to a JS Date object in service A:

{
  "input": {
    "id": "1234",
    "dob": "2000-01-01T00:00:00Z"
  }
}

Which fails validation.

You are already stripping the time component when serializing the GraphQL date. Can we do the same when parsing so that values can be passed from service to service?