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

Error: A type naming conflict has occurred - two entities have tried to define the same type #3848

Closed
MarkLyck opened this issue Apr 19, 2022 · 2 comments

Comments

@MarkLyck
Copy link
Contributor

Describe the bug
I'm running into a schema generation error when setting up postgraphile as a source.

(node:71168) ExperimentalWarning: stream/web is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
Configuration is not valid:
data/sources/0/handler/postgraphile/options must be object, data/sources/0/handler/postgraphile/options must be string, data/sources/0/handler/postgraphile/options must match a schema in anyOf
🕸️ - GetMesh: Getting subschemas from source handlers
🕸️ - CRM: Generating the schema
🕸️ - Server: Generating the unified schema...
🕸️ - CRM - PostgreSQL: checking client timeout
🕸️ - CRM - PostgreSQL: connecting new client
(node:71168) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.
🕸️ - CRM - PostgreSQL: new client connected
🕸️ - CRM - PostgreSQL: pulse queue
🕸️ - CRM - PostgreSQL: no queued requests
🕸️ - CRM: Failed to generate the schema
 Error: A type naming conflict has occurred - two entities have tried to define the same type 'Subscription'.

  The first entity was:

    Adding table type for table "public"."subscription". You can rename the table's GraphQL type via a 'Smart Comment':

      COMMENT ON TABLE "public"."subscription" IS E'@name newNameHere';

  The second entity was:

    graphile-build built-in (root subscription type)
    at Object.addType (/Users/marklyck/colony/graphql-mesh/node_modules/.pnpm/graphile-build@4.12.2_graphql@16.3.0/node_modules/graphile-build/src/makeNewBuild.js:319:17)
    at Object.newWithHooks (/Users/marklyck/colony/graphql-mesh/node_modules/.pnpm/graphile-build@4.12.2_graphql@16.3.0/node_modules/graphile-build/src/makeNewBuild.js:1019:14)
    at hook (/Users/marklyck/colony/graphql-mesh/node_modules/.pnpm/graphile-build@4.12.2_graphql@16.3.0/node_modules/graphile-build/src/plugins/SubscriptionPlugin.js:48:28)
    at SchemaBuilder.applyHooks (/Users/marklyck/colony/graphql-mesh/node_modules/.pnpm/graphile-build@4.12.2_graphql@16.3.0/node_modules/graphile-build/src/SchemaBuilder.js:411:20)
    at Object.newWithHooks (/Users/marklyck/colony/graphql-mesh/node_modules/.pnpm/graphile-build@4.12.2_graphql@16.3.0/node_modules/graphile-build/src/makeNewBuild.js:369:27)
    at SchemaBuilder.buildSchema (/Users/marklyck/colony/graphql-mesh/node_modules/.pnpm/graphile-build@4.12.2_graphql@16.3.0/node_modules/graphile-build/src/SchemaBuilder.js:494:28)
    at PostGraphileHandler.getMeshSource (/Users/marklyck/colony/graphql-mesh/node_modules/.pnpm/@graphql-mesh+postgraphile@0.20.9_graphql@16.3.0/node_modules/@graphql-mesh/postgraphile/index.js:97:32)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async /Users/marklyck/colony/graphql-mesh/node_modules/.pnpm/@graphql-mesh+runtime@0.33.13_graphql@16.3.0/node_modules/@graphql-mesh/runtime/index.js:39:28
🕸️: An error occured while writing the schema file: Error: Schemas couldn't be generated successfully. Check for the logs by running Mesh with DEBUG=1 environmental variable to get more verbose output.
    at Object.getMesh (/Users/marklyck/colony/graphql-mesh/node_modules/.pnpm/@graphql-mesh+runtime@0.33.13_graphql@16.3.0/node_modules/@graphql-mesh/runtime/index.js:69:15)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
🕸️: An error occurred while building the artifacts: Error: Schemas couldn't be generated successfully. Check for the logs by running Mesh with DEBUG=1 environmental variable to get more verbose output.
    at Object.getMesh (/Users/marklyck/colony/graphql-mesh/node_modules/.pnpm/@graphql-mesh+runtime@0.33.13_graphql@16.3.0/node_modules/@graphql-mesh/runtime/index.js:69:15)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
🕸️ - Server: Error: Schemas couldn't be generated successfully. Check for the logs by running Mesh with DEBUG=1 environmental variable to get more verbose output.
    at Object.getMesh (/Users/marklyck/colony/graphql-mesh/node_modules/.pnpm/@graphql-mesh+runtime@0.33.13_graphql@16.3.0/node_modules/@graphql-mesh/runtime/index.js:69:15)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
 ELIFECYCLE  Command failed with exit code 1.

This happens because there is a table in my database called subscription which causes a conflict with the root "Subscription" type.

I have tried 3 things to solve it. I have tried to transform it with rename

    transforms:
      - rename:
          renames:
            - from:
                type: Query
                field: subscription
              to:
                type: Query
                field: renamed_sub

I have tried to encapsulate it (which I want to do anyway)

    transforms:
       - encapsulate:
           applyTo:
             query: true
             mutation: false
             subscription: false

and I have tried to add a postgraphile "magic comment" in there. But unsurprisingly the mesh.yml file does not respect or use the postgraphile magic comments.

It looks to me like these transforms don't take any affect until AFTER the postgraphile schema has been generated, and the actual error is occouring during the postgraphile schema generation.

postgraphile has a clear fix for this, which is their "Smart comments", but I don't see any way to add these Smart comments when using graph mesh.

Is there any way to do that??? If not, there needs to be another way to tell postgraphile to rename this table.

To Reproduce
Create a postgres db with a table named "subscription".
Try to connect graph mesh to that posgres table via the @graphql-mesh/postgraphile package.
see error.

Expected behavior
I would expect there to be a way to tell postgraphile schema generator to rename the table "subscription" to something else to fix the conflict.

Environment:

"@graphql-mesh/cli": "^0.67.4",
"@graphql-mesh/graphql": "^0.23.6",
"@graphql-mesh/openapi": "^0.24.9",
"@graphql-mesh/postgraphile": "^0.20.9",
"@graphql-mesh/runtime": "^0.33.13",
"@graphql-mesh/transform-encapsulate": "^0.3.43",
"@graphql-mesh/transform-prefix": "^0.11.32",
"@graphql-mesh/transform-rename": "^0.12.33",
@MarkLyck
Copy link
Contributor Author

MarkLyck commented Apr 20, 2022

It seems this can be resolved by appending a relatively simple plugin like this:

const { makeJSONPgSmartTagsPlugin } = require("graphile-utils");

const renameSubscriptionPlugin = makeJSONPgSmartTagsPlugin({
  version: 1,
  config: {
    class: {
      subscription: {
        tags: {
          name: "renamed_subscription",
        },
      },
    },
  },
});

But the appendPlugins type only supports JSON or string... So the only way to "add" this it to publish my completely un-reusable plugin on npm and have it be installed that way 🤔 That seems like a pretty big workaround for built in plugin support.

Is there any other way to solve this? E.g. can you reference a plugin by filename?

@MarkLyck
Copy link
Contributor Author

Update: I figured out it does actually accept a local filepath as a valid string, and it works fine in dev mode.

But it breaks in production :( I created a seperate bug ticket for that issue here: #3886
Sadly for now I had to publish it as a seperate npm moodule and install it via package.json to use it.

I'm not sure if this issue is worth resolving, since there is a workaround by building a custom postgraphile plugin and adding it to appendPlugins. But hopefully the issue with local file paths breaking production build will be resolved 🤞

@MarkLyck MarkLyck closed this as completed May 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant