Closed mdazy closed 4 years ago
My schema specifies two scalars:
scalar Date scalar AnyObject input ServiceParametersInput { date: Date! serviceName: String! data: AnyObject }
However, the AnyObject field appears to be mocked as an actual type, without any mock function being generated for it, whereas the Date field is mocked "as expected" - although it's also presented as a typical custom scalar in the graphql doc:
AnyObject
Date
export const aServiceParametersInput = (overrides?: Partial<ServiceParametersInput>): ServiceParametersInput => { return { date: overrides && overrides.hasOwnProperty('date') ? overrides.date! : '1970-01-13T19:39:08.227Z', serviceName: overrides && overrides.hasOwnProperty('serviceName') ? overrides.serviceName! : 'praesentium', data: overrides && overrides.hasOwnProperty('data') ? overrides.data! : anAnyObject(), }; };
This results into a compile-time error when using the generated mocks file:
schema/lib/mocks.tsx:221:81 - error TS2304: Cannot find name 'anAnyObject'. 221 data: overrides && overrides.hasOwnProperty('data') ? overrides.data! : anAnyObject(), ~~~~~~~~~~~
For now I'm working around this by adding a dummy definition:
./schema/lib/mocks.tsx: plugins: - "graphql-codegen-typescript-mock-data": typesFile: "./clientTypes.tsx" addTypename: true # work around issue with mocking of custom scalars - add: const anAnyObject = ():any => null;
Thanks.
Thanks for the issue, would you be able to create a little reproduction repository? I'll try to check that during the week if I find some time
You can clone this one, I think I can't make it any shorter :) Thanks.
perfect thanks !
My schema specifies two scalars:
However, the
AnyObject
field appears to be mocked as an actual type, without any mock function being generated for it, whereas theDate
field is mocked "as expected" - although it's also presented as a typical custom scalar in the graphql doc:This results into a compile-time error when using the generated mocks file:
For now I'm working around this by adding a dummy definition:
Thanks.