Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

get only title and slug from page doc.

default discord avatar
bhavikak.2 years ago
20

hello ,


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

  • discord user avatar
    denolfe
    2 years ago

    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.2 years ago
    @967118574445547650

    can you share me reference.

  • discord user avatar
    denolfe
    2 years ago
    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.2 years ago

    hello

    @967118574445547650

    for execute graphql query need any other configuration?

  • discord user avatar
    denolfe
    2 years ago

    Everything should work out of the box

  • default discord avatar
    bhavikak.2 years ago

    okay i'll try thanks

    @967118574445547650

    for quick response.





    i'm getting error

  • discord user avatar
    denolfe
    2 years ago

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

  • default discord avatar
    bhavikak.2 years ago

    ok

    @967118574445547650

    got it.



    hello

    @967118574445547650

    i need help for execute graphql query.



    can you tell me what exactly need for it.

  • discord user avatar
    denolfe
    2 years ago

    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
    2 years ago
    @1043125033519820902

    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.



  • default discord avatar
    bhavikak.2 years ago

    hello

    @969226489549713438

    i fixed it but i got another error.





    @967118574445547650

    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.

  • discord user avatar
    dribbens
    2 years ago

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

  • default discord avatar
    bhavikak.2 years ago

    i call rest api and render data into table

  • discord user avatar
    dribbens
    2 years ago

    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.2 years ago


    your guess is right.



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

  • discord user avatar
    dribbens
    2 years ago

    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.2 years ago

    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
    2 years ago

    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.2 years ago

    but i need that custom component

  • discord user avatar
    dribbens
    2 years ago

    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.

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.