LiamMartens / sanity-plugin-intl-input

Intl input for Sanity with a cleaner UI than a default solution
MIT License
111 stars 22 forks source link

"Encountered anonymous inline object" deploying GraphQL #17

Open nickgriffiths opened 3 years ago

nickgriffiths commented 3 years ago

I've created a document with a field translation using the intl object:

export default {
  title: "Tag",
  name: "tag",
  type: "document",
  fields: [
    {
      name: "translatableName",
      type: "object",
      options: {
        i18n: true
      },
      fields: [
        {
          name: "name",
          type: "string",
          title: "Tag name"
        }
      ]
    }
  ],
  [ ... ]

When I run sanity graphql deploy I see the following error:

Error: Encountered anonymous inline object "translatableName" for field/type "Tag". To use this field with GraphQL you will need to create a top-level schema type for it. See https://docs.sanity.io/help/schema-lift-anonymous-object-type
    at createLiftTypeError (~/unilever/rexona/node_modules/@sanity/core/lib/actions/graphql/extractFromSanitySchema.js:499:13)
    at getObjectDefinition (~/unilever/rexona/node_modules/@sanity/core/lib/actions/graphql/extractFromSanitySchema.js:203:13)
[ ... ]

I tried creating a new type as recommended:

export default {
  name: "translatableName",
  type: "object",
  options: {
    i18n: true
  },
  fields: [
    {
      name: "name",
      type: "string",
      title: "Tag name"
    }
  ]
};
export default {
  title: "Tag",
  name: "tag",
  type: "document",
  fields: [
    {
      name: "myName",
      type: "translatableName"
    }
  ],
  [ ... ]

But now I don't see the translation UI, despite specifying i18n: true. It just looks like a normal object: image

Do you have any ideas on how I can resolve this please?

LiamMartens commented 3 years ago

@nickgriffiths I've published a beta version of the plugin (yarn install sanity-plugin-intl-input@beta) which addresses this issue; maybe you can test whether it works?

nickgriffiths commented 3 years ago

Thank you @LiamMartens, I will try and find some time to test this soon.