Search code examples
graphqlgithub-api

How do I query a GitHub Project Item title from GraphQL?


I'm attempting to use the GitHub ProjectV2 API to query a GitHub Projects beta project to obtain the title or a given GitHub Project Item.

Unfortunately, I'm not well-versed in GraphQL and struggling to complete the query. What am I missing from the following GraphQL query to get this to work?

query {
   node(id: \"PROJECT_NODE_ID\") { 
      ... on ProjectV2 { 
          items(id:\"PROJECT_ITEM_ID\") 
      } 
   } 
   content{ 
      ... on DraftIssue { 
          title 
      } 
   }
}

As written, this returns the following error:

Field must have selections (field 'items' returns ProjectV2ItemConnection but has no selections. Did you mean 'items { ... }'?)"}


Solution

  • You're almost there, but there are two issues here:

    1. items returns a Connection, which means you still need to include another set of curly braces to "select" which fields you'd like.

    2. The GitHub ProjectsV2 API doesn't look like it supports selection of individual items yet, only paginating through a list of items. This means that what you actually want to use is something like:

    query {
      node(id: \"PROJECT_NODE_ID\") {
        ... on ProjectV2 {
          items(first: 10) {
            nodes {
              content {
                ... on DraftIssue {
                  title
                }
              }
            }
          }
        }
      }
    }