Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gql typegen messaging updates #4491

Closed
wants to merge 1 commit into from

Conversation

Tobbe
Copy link
Member

@Tobbe Tobbe commented Feb 15, 2022

Fixes #4393

To recap, this is the error we're printing

gen | Generating TypeScript definitions and GraphQL schemas...
gen |
gen |       Unable to find any GraphQL type definitions for the following pointers:
gen |
gen |           - ./web/src/**/!(*.d).{ts,tsx,js,jsx}
gen |
gen |
gen |       Unable to find any GraphQL type definitions for the following pointers:
gen |
gen |           - ./web/src/**/!(*.d).{ts,tsx,js,jsx}
gen |
gen |
gen | Error: Could not generate GraphQL type definitions (web)
gen |
gen | 14 files generated

The "Unable to find..." error message comes from here: https://github.com/ardatan/graphql-tools/blob/2207fbcdacf708ee9836ee72d0c0f92dba0d0942/packages/load/src/load-typedefs.ts#L120

The "Error: Could not generate..." message is our own.

With errorsOnly: false we get a better idea of what's going on:

gen | Generating TypeScript definitions and GraphQL schemas...
gen | gene /Users/tobbe/tmp/typegen/web/types/graphql.d.ts
gen | [01:38:48] Parse configuration [started]
gen | [01:38:48] Parse configuration [completed]
gen | [01:38:48] Generate outputs [started]
gen | [01:38:48] Generate /Users/tobbe/tmp/typegen/web/types/graphql.d.ts [started]
gen | [01:38:48] Load GraphQL schemas [started]
gen | [01:38:48] Load GraphQL schemas [completed]
gen | [01:38:48] Load GraphQL documents [started]
gen | [01:38:48] Load GraphQL documents [failed]
gen | [01:38:48] →
gen |       Unable to find any GraphQL type definitions for the following pointers:
gen |
gen |           - ./web/src/**/!(*.d).{ts,tsx,js,jsx}
gen |
gen | [01:38:48] Generate /Users/tobbe/tmp/typegen/web/types/graphql.d.ts [failed]
gen | [01:38:48] →
gen |       Unable to find any GraphQL type definitions for the following pointers:
gen |
gen |           - ./web/src/**/!(*.d).{ts,tsx,js,jsx}
gen |
gen | [01:38:48] Generate outputs [failed]
gen |
gen | Error: Could not generate GraphQL type definitions (web)
gen |
gen | 14 files generated

@graphql-codegen is using Listr, and as you can see there are two tasks that fail with the same error message, that's why we get duplicated output. We get it for both "Load GraphQL documents" and "Generate /Users/tobbe/tmp/typegen/web/types/graphql.d.ts".

The first of those two is here: https://github.com/dotansimha/graphql-code-generator/blob/1e3d37a349a1d6748f235465a8bb78c66e0d1edf/packages/graphql-codegen-cli/src/codegen.ts#L261 and the other one is right after. And because they have exitOnError: true configured, as soon as the first of those two fails, so does the other one. And apparently the error carries over. If I switch it to exitOnError: false I only get one error output:

gen | Generating TypeScript definitions and GraphQL schemas...
gen | gene /Users/tobbe/tmp/typegen/web/types/graphql.d.ts
gen | [01:45:41] Parse configuration [started]
gen | [01:45:41] Parse configuration [completed]
gen | [01:45:41] Generate outputs [started]
gen | [01:45:41] Generate /Users/tobbe/tmp/typegen/web/types/graphql.d.ts [started]
gen | [01:45:41] Load GraphQL schemas [started]
gen | [01:45:41] Load GraphQL schemas [completed]
gen | [01:45:41] Load GraphQL documents [started]
gen | [01:45:41] Load GraphQL documents [failed]
gen | [01:45:41] →
gen |       Unable to find any GraphQL type definitions for the following pointers:
gen |
gen |           - ./web/src/**/!(*.d).{ts,tsx,js,jsx}
gen |
gen | [01:45:41] Generate [started]
gen | [01:45:41] Generate [completed]
gen | [01:45:41] Generate /Users/tobbe/tmp/typegen/web/types/graphql.d.ts [failed]
gen | [01:45:41] Generate outputs [failed]
gen |
gen | Error: Could not generate GraphQL type definitions (web)
gen |
gen | 14 files generated

But that's not something I can control, so we'll have to live with duplicated output from @graphql-codegen

@Tobbe
Copy link
Member Author

Tobbe commented Feb 16, 2022

I've created an issue report with @graphql-codegen here: dotansimha/graphql-code-generator#7546

Let's see what they say before we decide on next steps here.

@Tobbe
Copy link
Member Author

Tobbe commented Mar 7, 2022

Some notes from looking into this

The original issue had these reproduction steps:

yarn create redwood-app --ts my-app
cd my-app
yarn rw upgrade --tag canary
yarn rw dev

Instead of yarn rw dev I've found it easier to work with yarn rw g types as I can just let it run to finish. With yarn rw dev that took too long, so I would have to fire off a well-timed Ctrl+C instead.

A good entry-point for this in RW code is node_modules/@redwoodjs/internal/dist/generate/generate.js. We're interested in the call to generateTypeDefs. (Feel free to comment out the call to generateGraphQLSchema for less noise.)

generateTypeDefs is in node_modules/@redwoodjs/internal/dist/generate/typeDefinitions.js and we're only interested in the call to generateTypeDefGraphQLWeb which will call runCodegenGraphQL which will in turn call async function generate(input, saveToFile = true) in node_modules/@graphql-codegen/cli/index.js

generate() -> executeCodegen -> 'Load GraphQL documents' task

rootDocuments is []
outputSpecificDocments is [ './web/src/**/!(*.d).{ts,tsx,js,jsx}' ]

'Load GraphQL documents' task -> context.loadDocuments -> loadDocuments(pointer, config) -> load.loadDocuments -> node_modules/@graphql-tools/load/index.js loadDocuments -> loadTypedefs -> prepareResult

validSources is [] -> throw new Error(...)

validSources is [] because sources is [] in loadTypedefs

pointerOptionMap is { './web/src/**/!(*.d).{ts,tsx,js,jsx}': {} }
options is

{
  sort: true,
  skipGraphQLImport: true,
  ignore: [
    '/Users/tobbe/tmp/rw4393/Users/tobbe/tmp/rw4393/web/types/graphql.d.ts'
  ],
  loaders: [
    CodeFileLoader { config: [Object] },
    GitLoader {},
    GithubLoader {},
    GraphQLFileLoader {}
  ],
  cwd: '/Users/tobbe/tmp/rw4393',
  schema: '/Users/tobbe/tmp/rw4393/.redwood/schema.graphql',
  config: {
    namingConvention: 'keep',
    scalars: {
      BigInt: 'number',
      DateTime: 'string',
      Date: 'string',
      JSON: 'Record<string, unknown>',
      JSONObject: 'Record<string, unknown>',
      Time: 'string'
    },
    omitOperationSuffix: true
  },
  generates: {
    '/Users/tobbe/tmp/rw4393/web/types/graphql.d.ts': {
      documents: './web/src/**/!(*.d).{ts,tsx,js,jsx}',
      plugins: [Array]
    }
  },
  silent: false,
  errorsOnly: false,
  pluginContext: {},
  namingConvention: 'keep',
  scalars: {
    BigInt: 'number',
    DateTime: 'string',
    Date: 'string',
    JSON: 'Record<string, unknown>',
    JSONObject: 'Record<string, unknown>',
    Time: 'string'
  },
  omitOperationSuffix: true
}

I'll try and see if I can call loadDocuments from our own code. It's documented here https://www.graphql-tools.com/docs/api/modules/load_src#loaddocumentssync

Will continue tomorrow

@Tobbe
Copy link
Member Author

Tobbe commented Mar 12, 2022

Alternative (better, imo) solution over here: #4728

@thedavidprice
Copy link
Contributor

@Tobbe seems like this one is now ok to close out, correct?

@Tobbe
Copy link
Member Author

Tobbe commented Mar 18, 2022

@Tobbe seems like this one is now ok to close out, correct?

Yes

@Tobbe Tobbe closed this Mar 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Archived
Development

Successfully merging this pull request may close these issues.

Errors on initial yarn rw dev
2 participants