tgriesser / cypress-graphql-mock

Adds commands for executing a mocked GraphQL server using only the client
171 stars 43 forks source link

Cannot Handle Cusomt Scalars #17

Closed s-r-jones closed 5 years ago

s-r-jones commented 5 years ago

I am importing my schema as one big json object and seeing this error when I try to run the command.

GraphQL error: No mock defined for type "DateTime"

To reproduce, add the custom DateTime scalar as a type to one of your properties.

dmtrKovalenko commented 5 years ago

It is possible with

DateTime(obj, args, context, field) {
    if (obj[field.fieldName]) return obj[field.fieldName]
    return new Date('2019-01-01')
  },
s-r-jones commented 5 years ago

@dmtrKovalenko Thanks for your help. Where would I put this code? Like mockgraphqlOptions({mocks: DateTimeResolver })

sean6bucks commented 5 years ago

For anyone hitting finding this issue and finding it a bit confusing on where to add the scalar type resolver, it can be defined in the mockGraphql() config under mocks

cy.mockGraphql({
    ...
    mocks: {
        DateTime: () => new Date()
    }
})