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

You cannot register duplicate Types to the Schema #552

Open
ttstauss opened this issue Jun 1, 2022 · 3 comments
Open

You cannot register duplicate Types to the Schema #552

ttstauss opened this issue Jun 1, 2022 · 3 comments
Labels
bug Something isn't working has jira needs development Requires adjustments to the source code

Comments

@ttstauss
Copy link

ttstauss commented Jun 1, 2022

When creating a model that has two very similar relationship fields set up (i.e. a one to many and a many to many to the same model), graphql returns the following error AFTER the model name is updated:

You cannot register duplicate Types to the Schema. The Type '[NameOfField]ConnectionEdge' already exists in the Schema. Make sure to give new Types a unique name.

To reproduce

  1. Spin up a new WordPress.
  2. Add the Atlas Content Modeler & WPGraphQL plugins.
  3. Set up a Model (Faculty/Faculty Members).
  4. Set up another Model (Department/Departments) with a title field).
  5. Create two departments.
  6. In the Faculty model, add One to Many relationship to departments (called Primary Department as a required field).
  7. In the Faculty model, add Many to Many relationship to departments (called Other Departments not required).
  8. Create a faculty member and add a Primary department and any number of Other departments.
  9. Test the query in GraphiQL. Should work perfectly (department titles are accessible).
  10. Go to the Faculty model and update the model Singular Name and Plural Name to Person and People respectively.
  11. Go back to GraphiQL and test the query with the new name, will return null (if you turn on debugging you see the error from above).

Here's an example query:

query getPerson {
  person(id: "8", idType: DATABASE_ID) {
    otherDepartments {
      nodes {
        title
      }
    }
    primaryDepartment {
      node {
        title
      }
    }
  }
}

And an example result:

{
  "data": {
    "person": {
      "otherDepartments": {
        "nodes": null
      },
      "primaryDepartment": {
        "node": null
      }
    }
  },
  "extensions": {
    "debug": [
      {
        "type": "DUPLICATE_TYPE",
        "message": "You cannot register duplicate Types to the Schema. The Type 'PersonToDepartmentConnectionEdge' already exists in the Schema. Make sure to give new Types a unique name.",
        "type_name": "PersonToDepartmentConnectionEdge",
        "stack": [
          "C:\\Users\\User\\Local Sites\\acm\\app\\public\\wp-content\\plugins\\wp-graphql\\src\\Registry\\TypeRegistry.php:606",
          "C:\\Users\\User\\Local Sites\\acm\\app\\public\\wp-content\\plugins\\wp-graphql\\src\\Registry\\TypeRegistry.php:632",
          "C:\\Users\\User\\Local Sites\\acm\\app\\public\\wp-content\\plugins\\wp-graphql\\src\\Type\\WPConnectionType.php:327",
          "C:\\Users\\User\\Local Sites\\acm\\app\\public\\wp-content\\plugins\\wp-graphql\\src\\Type\\WPConnectionType.php:473",
          "C:\\Users\\User\\Local Sites\\acm\\app\\public\\wp-content\\plugins\\wp-graphql\\src\\Registry\\TypeRegistry.php:1015",
          "C:\\Users\\User\\Local Sites\\acm\\app\\public\\wp-content\\plugins\\wp-graphql\\access-functions.php:370",
          "C:\\Users\\User\\Local Sites\\acm\\app\\public\\wp-includes\\class-wp-hook.php:307",
          "C:\\Users\\User\\Local Sites\\acm\\app\\public\\wp-includes\\class-wp-hook.php:331",
          "C:\\Users\\User\\Local Sites\\acm\\app\\public\\wp-includes\\plugin.php:476",
          "C:\\Users\\User\\Local Sites\\acm\\app\\public\\wp-content\\plugins\\wp-graphql\\src\\Registry\\TypeRegistry.php:520",
          "C:\\Users\\User\\Local Sites\\acm\\app\\public\\wp-includes\\class-wp-hook.php:307",
          "C:\\Users\\User\\Local Sites\\acm\\app\\public\\wp-includes\\class-wp-hook.php:331",
          "C:\\Users\\User\\Local Sites\\acm\\app\\public\\wp-includes\\plugin.php:476",
          "C:\\Users\\User\\Local Sites\\acm\\app\\public\\wp-content\\plugins\\wp-graphql\\src\\Registry\\TypeRegistry.php:231",
          "C:\\Users\\User\\Local Sites\\acm\\app\\public\\wp-content\\plugins\\wp-graphql\\src\\Registry\\SchemaRegistry.php:38",
          "C:\\Users\\User\\Local Sites\\acm\\app\\public\\wp-content\\plugins\\wp-graphql\\src\\WPGraphQL.php:678",
          "C:\\Users\\User\\Local Sites\\acm\\app\\public\\wp-content\\plugins\\wp-graphql\\src\\Request.php:151",
          "C:\\Users\\User\\Local Sites\\acm\\app\\public\\wp-content\\plugins\\wp-graphql\\src\\Router.php:459",
          "C:\\Users\\User\\Local Sites\\acm\\app\\public\\wp-content\\plugins\\wp-graphql\\src\\Router.php:265",
          "C:\\Users\\User\\Local Sites\\acm\\app\\public\\wp-includes\\class-wp-hook.php:307",
          "C:\\Users\\User\\Local Sites\\acm\\app\\public\\wp-includes\\class-wp-hook.php:331",
          "C:\\Users\\User\\Local Sites\\acm\\app\\public\\wp-includes\\plugin.php:524",
          "C:\\Users\\User\\Local Sites\\acm\\app\\public\\wp-includes\\class-wp.php:398",
          "C:\\Users\\User\\Local Sites\\acm\\app\\public\\wp-includes\\class-wp.php:770",
          "C:\\Users\\User\\Local Sites\\acm\\app\\public\\wp-includes\\functions.php:1330",
          "C:\\Users\\User\\Local Sites\\acm\\app\\public\\wp-blog-header.php:16",
          "C:\\Users\\User\\Local Sites\\acm\\app\\public\\index.php:17"
        ]
      }
    ]
  }
}

Expected behavior

The query should still work even after the model name is changed.

Screenshots

Version information

  • Plugin version: 0.17.0 (Atlas Content Modeler); 1.8.2 (WP GraphQL)
  • WordPress version: 6.0
  • Operating system: Windows 10 Pro
  • Browser: Chrome

Additional context

@ttstauss ttstauss added the bug Something isn't working label Jun 1, 2022
@nickcernis
Copy link
Member

nickcernis commented Jun 3, 2022

Thanks for reporting this, @ttstauss! I'm able to reproduce this now.

I've found two separate issues:

  1. Relationships resolve as null if the source model (the “A” in the A->B relationship) has a mismatching Singular Name and Model ID. (I can reproduce this by setting up a model with a slug of 'test' and a singular name of 'other', even without renaming the model.
  2. Multiple relationship fields on one model that point to the same other model result in a DUPLICATE_TYPE warning with a “You cannot register duplicate Types to the Schema” message. (I can reproduce the error you describe without changing the model name.)

We'll look into some fixes. Until then, the workarounds are to:

  1. Keep the original Singular/Plural model names to prevent the null response.
  2. Ignore the DUPLICATE_TYPE messages in debug output. (They are warnings and should not impact query results.)

@nickcernis nickcernis added the needs development Requires adjustments to the source code label Jun 3, 2022
@ttstauss
Copy link
Author

ttstauss commented Jun 6, 2022

@nickcernis, thanks for looking into this. We'll revert to the original Singular/Plural modal names for now.

Looking forward to a fix. Thanks!

@nickcernis
Copy link
Member

As of ACM 0.18.0 (out now) it should now be possible to change the name of a model without relationships resolving as null.

I'll leave this open until we fix the DUPLICATE_TYPE warnings too, though, which should not impact behavior but should still be resolved. (Note for team: we're tracking this internally at https://wpengine.atlassian.net/browse/MTKA-1543.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working has jira needs development Requires adjustments to the source code
Projects
None yet
Development

No branches or pull requests

2 participants