Currently involved in a TypeScript project that utilizes typescript-mock-data
for mock data generation. Within my codegen.ts
file, I have configured the onlyOperationTypes: true
setting to specifically generate mock data for operation types.
However, upon executing the code generation process, the desired outcome is not achieved. It appears that while onlyOperationTypes functions properly for graphql.ts files, it ends up removing all values from the mockers file. Despite confirming that other configuration options are functioning as intended.
I have referred to the documentation for typescript-mock-data
, yet there seems to be a lack of specific information regarding the utilization of onlyOperationTypes. Has anyone effectively implemented onlyOperationTypes with typescript-mock-data in a TypeScript project? If so, could you offer guidance on how to correctly set up this feature?
const config: CodegenConfig = {
overwrite: true,
hooks: {
afterAllFileWrite: ['prettier --write'],
},
generates: {
[TYPES_FILE]: {
schema: graphQLEndpoint,
documents: GRAPHQL_DOCUMENT_LOCATIONS,
plugins: [
{
add: {
content: [autoGeneratedHeader],
},
},
'typescript',
'typescript-operations',
'typescript-react-apollo',
],
config: {
avoidOptionals: {
field: true,
object: true,
defaultValue: true,
},
namingConvention: {
typeNames: 'keep',
enumValues: 'change-case-all#upperCase',
},
exportFragmentSpreadSubTypes: true,
preResolveTypes: true,
// onlyOperationTypes: true,
},
},
[MOCKERS_FILE]: {
schema: graphQLEndpoint,
documents: GRAPHQL_DOCUMENT_LOCATIONS,
plugins: [
{
add: {
content: [autoGeneratedHeader],
},
},
{
'typescript-mock-data': {
typeNames: 'keep',
enumValues: 'change-case-all#upperCase',
terminateCircularRelationships: true,
},
},
],
config: {
withHooks: false,
withComponent: false,
scalars: {
Time: 'string',
},
typesFile: 'src/services/graphql/generated/graphql.ts',
avoidOptionals: {
field: true,
object: true,
defaultValue: true,
},
namingConvention: {
typeNames: 'keep',
enumValues: 'change-case-all#upperCase',
},
defaultScalarType: 'unknown',
preResolveTypes: true,
// onlyOperationTypes: false,
},
},
},
};