Closed arnonate closed 2 years ago
Hi, Thanks for the report
I'm not sure to understand your issue, but that's probably a bug on our side.
It's probably related to this if that skips the generation of mock data for Query
and Mutation
types
Ha! That looks like the culprit for sure! For now I just wrote a small codegen plugin that writes the missing import and type that I need. Is there a reason to skip Query and Mutation types?
Yeah because it didn't make sense to create a mock aQuery
or aMutation
For me, you need to create a mock for a specific query, you don't want to mock the whole Query
object
So maybe it's the generation of aQuery()
that don't make sense? not sure
Ha! That looks like the culprit for sure! For now I just wrote a small codegen plugin that writes the missing import and type that I need. Is there a reason to skip Query and Mutation types?
Care to share what you've learned? I, too, am getting this issue and i understand why it's being omitted as what @ardeois stated. How do we go about fixing this?
@naknode Can you share your use case as of why you would need aQuery
?
@naknode Can you share your use case as of why you would need
aQuery
?
@ardeois Sorry, I miswrote. I do not need aQuery
. As you states, it is not needed for practical purposes. How should I proceed with eliminating a bunch of Cannot find name aQuery errors.
Great library, btw!
Ah sorry I understand your issue now.
This should be fixed in this plugin. We would probably need to property import Query
when it's used as a type, but don't generate aQuery
Or the easiest way is to keep generating aQuery
and aMutation
as it indeed can be used as an output type (as @arnonate shows in his example)
You can do a PR to update this logic https://github.com/ardeois/graphql-codegen-typescript-mock-data/blob/3d2e6791b9ab762540f48037d611b53cf2930320/src/index.ts#L391-L393
@ardeois I am on the latest 1.5.7.
so I should already have the PR you are requesting. I see it in my local node_modules
, too. So this should already be fixed, no?
Can you show me where @arnonate is using it as a output type? I'm not an expert-level GraphQLer but I understand the fundamentals. :-) Thank you
Also, it keeps generating imports of UUID
and JSON
filters as UUIDFilter
and JSONFilter
, is there anyway to correct the import through this plugin's config?
Thanks again!
@naknode I just wrote a small plugin that appends this to the output:
// codedgen-plugin.js
module.exports = {
plugin: (schema, documents, config) => {
return `// Custom codegen-plugin output
import { Query } from './graphql';
const aQuery = (overrides: Partial<Query>, omit: Set<string>): Query | null | undefined => overrides ? overrides as Query : undefined;`;
},
};
It's not a perfect solution, but I am not actually mocking aQuery anywhere, just needed to get rid of the errors. Here is the plugin in my .graphqlrc
:
'src/generated/mocks.ts':
plugins:
- typescript-mock-data:
typesFile: './graphql.tsx'
enumValues: pascal-case#pascalCase
terminateCircularRelationships: true
addTypename: true
typenames: keep
scalars:
Date: date
Datetime:
generator: date
arguments: 'YYYY-MM-DDTHH:mm:ss.SSS\Z'
- codegen-plugin.js
Hello! Thanks for the script. I am seeing one issue with my schema. Mutation payloads have an optional
query
field that is not getting generated in the output mocks file. See screenshot below:If you can point me in the right direction I will happily contribute a solution. I am just not sure if I have my codegen options set correctly or if this will require a pull request.