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

Unable to access reference object properties on createSchemaCustomization #146

Open
AbdallahAbis opened this issue Feb 20, 2022 · 0 comments

Comments

@AbdallahAbis
Copy link

I'm trying to add a custom field to my SanityDocument by using createSchemaCustomization API, the new field will combine a few SanityDocument fields in one, but one of those fields is a reference field and on sanity GROQ it could be accessed like brand->name but on I don't know how to access it on createSchemaCustomization.

My createSchemaCustomization:

exports.createSchemaCustomization = ({ actions, schema }) => {
  actions.createTypes([
    schema.buildObjectType({
      name: "SanityDocument",
      interfaces: ["Node"],
      fields: {
        title: {
          type: "String!",
          resolve: (source) => {
            console.log(source.brand)
            return `${source.model} ${source.brand.name}`
          }
        },
      },
    }),
  ]);
};

This doesn't work, logging source.brand outputs

"brand":{
  "_ref":"brand-36fef2ab-a5a0-472d-ac92-0f14cb9cae6b"
  "_type":"reference"
}
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