Extending type for GrahQL

default discord avatar
b-barry
7 months ago
2 1

Hello all,

I read about the "Adding your own Queries and Mutations" but I didn't find any explanation about extending an existing type.
For example, I have collection called product where I have shopifyId field.
I would like to be able to update the product query to able to have a node "shopify"

{
  products {
    shopifyId
    shopify {
      price
    }
  }
}

Do you have way?

I was thinking to override the schema, I found the code but we should provide a way to merge the schema using for example @graphql-tools/merge

  • discord user avatar
    jmikrut
    Payload Team
    7 months ago

    Hey @b-barry — you should not directly modify the auto-generated GraphQL types, but what you're doing should be possible by adding a field to your config itself. You can then set admin.disabled: true on the field to have it hide from the admin UI entirely. And then you could fill the field's value dynamically with hooks / similar, therefore treating it as a "virtual field". We have a demo of this coming out shortly, so keep an eye out!

    3 replies
  • default discord avatar
    b-barry
    7 months ago

    Thanks for the quick response. About the hidden field, do you plan to save it the database ?
    I prefer not to be sure to have the latest data

  • discord user avatar
    jmikrut
    Payload Team
    7 months ago

    You don’t need to save the field to the database, and you can populate it dynamically with hooks. That’s actually what I was intending and is a pattern that we use ourselves quite a bit. It works well and accomplishes exactly what you’re looking to do 👍

  • default discord avatar
    b-barry
    7 months ago

    Super ! I am looking forward for your example.

    Thanks again for the response

Open the post
Continue the discussion in GitHub
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.