Getting this error when trying to view the GraphQL playground. Originally I had created a Countries collection, which created a Country type, and there was also a block called Country as well. However I removed the block and there's only a single Country type in my payload-types.ts file, but I'm still getting this error. I also get the error when I run npm run generate:schema. Any tips on how to find where this other type is coming from? Or is there some rebuild process that needs to happen first? Thank you!
#Error: Schema must contain uniquely named types but contains multiple types named "Country".
31 messages · Page 1 of 1 (latest)
Help is on the way! To mark it as solved, use the /solve command. In the meantime, here are some existing threads that may help you:
Documentation:
I just ran into the same issue and finally found the culprit.
This is probably a little late for you, but might help anyone running into this issue in the future.
I am assuming, that you are using the plugin @payloadcms/plugin-form-builder.
I'm not too familiar with the inner workings of the plugin, but here's my guess as to what is happening:
The plugin defines a country field by default, which causes the creation of a Country block under the hood with the slug countries. This in turn creates a type Country in the GraphQL schema which then collides with your collection that has the same slug.
If you do not require this block then you can simply disable the field in the plugins config.
// plugins/index.ts
formBuilderPlugin({
fields: {
country: false, // this will prevent the error
},
// ...
)
Since this was enough for me I didn't look any further. Perhaps there's a way to rename the slug.
Why anyone would think it was a good idea to block a slug name like countries or states is beyond me.
we cant predict what other collections or blocks or types you might have
so we always run with the simplest non interefering option out of the box
you can pass in an object to country there to override the block
and then use something like graphQL.singularName and/or interfaceName to customise the typescript type too
@mossy sky Thanks, this configuration now works!
// plugins/index.ts
formBuilderPlugin({
fields: {
payment: false,
country: {
interfaceName: 'CountryField',
},
},
// ...
)
This is indirectly mentioned in the docs here (https://payloadcms.com/docs/plugins/form-builder#fields-option) and here (https://payloadcms.com/docs/fields/blocks#block-configs) if you put 1 and 1 together.
Might it be worth adding a warning/info block to the docs here (https://payloadcms.com/docs/plugins/form-builder#fields-option) explaining that this kind of collision can occur and this is the way to fix it?
I can open a PR.
yeah ill take a PR, thanks!
ill give you some feedback here
country: {
interfaceName: 'CountrySelect',
},
Add a comment explaining // example overridding the generated type for this block
And change CountrySelect to CountryFormBlock
__Select can be generated from a collection too for our select API
Some field names defined by this plugin may result in GraphQL type name collisions with your own Blocks or Collections.
Example: `Error: Schema must contain uniquely named types but contains multiple types named "Country"`.
To resolve this, you can:
1. Change the `slug` in your [Collection Config](https://payloadcms.com/docs/configuration/collections#config-options)
2. Override `graphQL.singularName` in your [Collection Config](https://payloadcms.com/docs/configuration/collections#graphql)
3. Override `interfaceName` in your [Block Config](https://payloadcms.com/docs/fields/blocks#block-configs)
4. Override `interfaceName` in the plugin's field config, as shown above
Reworked to an info banner instead of warning
In the case that any fields from this plugin interfere with other blocks, globals or collections in your config via generated types or schema you can fix this by overriding the interface names:
- `interfaceName` in the plugin's field config
- `graphQL.singularName` if it interferes with GraphQL schema
generally it would make more sense to override this plugin's fields/blocks to something more specific like CountryFormField than to rename your country collection or something
and this makes it more succinct
ill copy this into the PR
Thank you for your input. I'm updating it as we speak.
I would like to keep the example though, as this is what will lead people to the part of the docs they're most likely in need of.
ahh the error
it just doesnt belong in a banner thats all
how about this then
remove all your changes and add a new sub-heading
"Resolving name conflicts with generated schema" - maybe word it a bit better
Then lead with the description -> example error > list > example code with override
Good idea, I'll update it in a bit
Ok, I made those changes. I’m happy to tweak it further if needed, but feel free to make any edits yourself if that speeds things up 🙂
ok it looks good to me, just nitpicks
- the title shouldnt be capitalised like that, only the first word
also it looks like for blocks we've deprecated that graphql prop in favour of using just the interfaceName
so maybe we shouldnt recommend graphQL at all and only interfaceName in case we change it for 4.0
In case of collections graphQL.singularName is currently the only option it seems, I'll add a third bullet point specifically for interfaceName in the block configuration.
And thanks for the nitpicking, the next update to the docs will be smoother (hopefully)