Open trixobird opened 10 months ago
You don't need to print the schema or pass the schema itself directly. You can just give the path to the schema. I guess "./schema" in your case
Tried schema: './schema/index.js',
and schema: './schema',
in both cases the error is:
Generate outputs
❯ Generate to ./src/schema/generated/schema.graphql
✖
Failed to load schema from ./schema:
Unable to find any GraphQL type definitions for the following pointers:
- ./schema
Error:
Unable to find any GraphQL type definitions for the following pointers:
- ./schema
Which makes sense to me; I am using a code first approach, shouldn't the schema be first compiled to a *.graphql file? That is whay the printSchema function of pothos is trying to do
Not sure exactly where the bug is, but it has something to do with how modules are loaded by graphql-codegen.
I initially assumed it was an upstream issue in jiti, but it looks like it might be more complicated: codegen.ts
import * as PothosExports from '@pothos/plugin-errors';
console.log(PothosExports)
export default {}
> pnpm graphql-codegen-esm --config src/schema/codegen.ts
{ default: 'errors' }
> pnpm jiti src/schema/codegen.ts
{
default: [Getter],
capitalize: [Getter],
defaultGetResultName: [Getter],
defaultGetUnionName: [Getter],
unwrapError: [Getter],
PothosErrorsPlugin: [Getter]
}
tracked down the issue, https://github.com/unjs/mlly/blob/main/src/cjs.ts#L38 sourceModule.default
is a string, and then it tries to use that default export as the new export object to assign properties to.
opened an issue here: https://github.com/unjs/mlly/issues/194
I'm running into this issue after switching to the turbo
option of Next.js, any insight into what might be going on?
Which packages are impacted by your issue?
@graphql-codegen/cli, @graphql-codegen/core
Describe the bug
I was trying the error plugin along with the ScopeAuthPlugin and everything is working on the server side. I tried to execute the codegen and I am gettting
PothosSchemaError: Received undefined as a type ref.
This is often caused by a circular import If this ref is imported from a file that re-exports it (like index.ts) you may be able to resolve this by importing it directly from the file that defines it. If I replace schema: printSchema(schema), in codegen with `schema: 'http://localhost:4000/graphql', the codegen works.
I have a sample repo that the issue is reproducable: https://github.com/trixobird/typescript_playground/tree/pothos-codegen-auth-bug. Just execute the codegen script pnpm codegen
Initially I thought that this is a pothos error, so I opened an issue there. Hayes came back saying that "This is a bug in graphql-code-generator (or more accurately, whatever they use to load typescript). After some debugging, I found that their loader doesn't expose any named exports if you also have a default export."
Your Example Website or App
https://github.com/trixobird/typescript_playground/tree/pothos-codegen-auth-bug
Steps to Reproduce the Bug or Issue
Expected behavior
I expected to have the codegen passed successfully, instead I am seeing the following error:
Screenshots or Videos
No response
Platform
graphql
version: 16.8.1Codegen Config File
import type { CodegenConfig } from '@graphql-codegen/cli'; import { printSchema } from 'graphql'; import schema from './index.js';
const config: CodegenConfig = { schema: printSchema(schema), emitLegacyCommonJSImports: false, generates: { './src/schema/generated/schema.graphql': { plugins: ['schema-ast'], }, }, config: { scalars: { Date: 'Date', UUID: 'string', }, }, }; export default config;
Additional context
No response