get only title and slug from page doc.

default discord avatar
bhavikak
last month
41

hello ,


is it possible to get only title and slug from page doc.

  • discord user avatar
    denolfe
    Payload Team
    last month

    With the REST endpoints, there is currently not a way to say what specific fields you want returned. Sounds like you may want to explore using the GraphQL endpoints. This is standard with GraphQL.

  • default discord avatar
    bhavikak
    last month

    @denolfe can you share me reference.

  • discord user avatar
    denolfe
    Payload Team
    last month
    https://payloadcms.com/docs/graphql/overview#graphql-overview

    Also, you should be able to open

    http://localhost:3000/api/graphql-playground

    on most payload projects to play around with the API calls.



    A query would look something like this:


    query {
      allPosts {
        title
        slug
      }
    }
  • default discord avatar
    bhavikak
    last month

    hello @denolfe for execute graphql query need any other configuration?

  • discord user avatar
    denolfe
    Payload Team
    last month

    Everything should work out of the box

  • default discord avatar
    bhavikak
    last month

    okay i'll try thanks @denolfe for quick response.





    i'm getting error

    image.png
  • discord user avatar
    denolfe
    Payload Team
    last month

    You'll want to use GraphQL's completion to aid in your queries

  • default discord avatar
    bhavikak
    last month

    ok @denolfe got it.



    hello @denolfe i need help for execute graphql query.



    can you tell me what exactly need for it.

  • discord user avatar
    denolfe
    Payload Team
    last month

    This is a bit vague of a request. What are you having trouble with specifically? Payload's GraphQL endpoint is just like any other GraphQL endpoint. If you need help forming queries, I'd suggest heading over to the GraphQL site to learn the basics. If you have something that is Payload-specific, happy to help.



    Examples of queries can be seen in our Website repo here:

    https://github.com/payloadcms/website/tree/main/src/graphql
  • discord user avatar
    dribbens
    Payload Team
    last month

    @bhavikak I can see from the screenshot graphql is having trouble with some of your config. Enums are specifically used in

    select

    and

    radio

    field types. Instead of

    true

    or

    false

    you will have to use

    1

    ,

    'true'

    , or

    0

    ,

    null

    or

    'false'

    to represent true/false instead of a boolean.



    image.png
  • default discord avatar
    bhavikak
    last month

    hello @dribbens i fixed it but i got another error.





    @denolfe my query don't work in graphql playground. so i thought i missed some configuration or anything else so that's why i'm asking.



    manage_category is a global config and it's my custom component.

    image.png
  • discord user avatar
    dribbens
    Payload Team
    last month

    What do you have configured for that field? I don't need the component code.

  • default discord avatar
    bhavikak
    last month

    i call rest api and render data into table

  • discord user avatar
    dribbens
    Payload Team
    last month

    There is something in your field that is causing a problem with the GraphQL generation



    What is the type?



    What other properties do you have in that field?



    It sounds like a group with no fields by the error I'm guessing but that isn't valid for payload and should throw an error on start



    Just paste the config here and I can better understand

  • default discord avatar
    bhavikak
    last month


    your guess is right.



    but don't know what's the issue. in config.

  • discord user avatar
    dribbens
    Payload Team
    last month

    A global with no fields seems to be your issue.



    What are you trying to do with that exactly?



    It won't be useful without any fields



    We don't validate the config to prevent that but we probably should.

  • default discord avatar
    bhavikak
    last month

    i'm just calling api and render data into table.



    and for render data in tabular format i use a third-party package.

  • discord user avatar
    dribbens
    Payload Team
    last month

    Can you remove manage categories from your globals? I don't see how it could be doing anything



    That should fix the issue with GraphQL on your project.

  • default discord avatar
    bhavikak
    last month

    but i need that custom component

  • discord user avatar
    dribbens
    Payload Team
    last month

    I see. Well the workaround then is that you give it some silly placeholder field to satisfy GraphQL. The field itself doesn't matter, but that empty

    fields

    array is definitely your issue.

Open the post
Continue the discussion in Discord
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.