Update github repository description via graphql - graphql

This is the GraphQL query for GitHub's API:
mutation {
updateProject(input: {
projectId: "MDEwOlJlcG9zaXRvcnkxMTY0ODYzMDc",
body: "Testing tusting",
state: OPEN
}) {
clientMutationId
}
}
I'm getting this error message:
"message": "Could not resolve to Project node with the global id of 'MDEwOlJlcG9zaXRvcnkxMTY0ODYzMDc'.",
What is wrong here? I'm trying to update a repository description.

Your question title mentions "repository description", but the GraphQL query is full of "project" references. If you want to update a repo description, you need to use mutation updateRepository.

Related

Updating meta fields in Shopify with GrapQL

I've never used GraphQL before so I am really lacking knowledge on how to go about this. I'm wanting to update product meta fields on Shopify and it appears this is the only way. What I've done so far is really fumbling...
My JSON is:
{
"input": {
"id": "gid://shopify/Product/749521178847",
"metafields": [
{
"id": "gid://shopify/Metafield/2223333",
"value": "Training Grounds"
}
]
}
}
I've minified this to:
{"input":{"id":"gid://shopify/Product/749521178847","metafields":[{"id":"gid://shopify/Metafield/2223333","value":"The Training Grounds"}]}}
And am then using an HTTP request to:
https://MYSTORE.myshopify.com/api/2021-10/graphql.json?query={"input":{"id":"gid://shopify/Product/749521178847","metafields":[{"id":"gid://shopify/Metafield/2223333","value":"The Training Grounds"}]}}
I get the error:
SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
I don't know if any of this is correct. If it is, I don't know if ?query= is the right variable to pass it through on.
I recommend you start using Postman, thunder client, or similar to write your graphql queries first, you will learn a lot about how graphql works and the error msgs will be a lot more useful.
To easily connect with Shopify on this stage, go to a store and create a private app, now you can use this for authenticating your API calls.
After that the Shopify graphql works on POST, you can't write your request on GET mode.
It needs to be a POST and you are missing type of operation mutation in this case and what it is.
Postman has https://www.postman.com/lively-moon-541169/workspace/purego-apis/example/16545848-bf0d1589-09b1-4ec6-ba63-a65a56b500eb examples of how to do the calls which can help you.
Also you can check GraphiQL app on shopify to test all the queries before making the programmatic queries
Updating an existing metafield:
mutation {
metafieldsSet(metafields: [
{namespace: "YOURNAMESPACE", ownerId: "gid://shopify/Customer/CUSTOMER_ID", type: "single_line_text_field", key: "YOURKEY", value: "THIS IS NEW VALUE"}
]) {
metafields {
key
value
}
userErrors {
field
message
}
}
}
Creating new metafield:
mutation {
customerUpdate(input: {
id: "gid://shopify/Customer/CUSTOMER_ID",
metafields: [
{key: "newkey", value: "some value", type: "single_line_text_field", namespace: "some namespace"},
]
}) {
userErrors {
field
message
}
}
}

How can I create an issue with github GraphQL API?

I'm starting to use GraphQL API and I've seen that the mutation createIssue was recently added but I don't know how to use it. I've tried the following but I'm getting errors:
mutation {
createIssue(input:{
repositoryId:"XXXXXXXXXXXX",
assigneeIds:"XXXXXXX",
title:"TestIssue",
body:"Not able to create an issue"})
}
You need first to get the repository id using the following request:
query FindRepo {
repository(owner: "johndoe", name: "awesome-repo") {
id
}
}
Then you call the mutation request by replacing the id you've got in the response in repositoryId field :
mutation CreateIssue {
createIssue(input: {repositoryId: "[ID from previous call]", title: "TestIssue", body: "Not able to create an issue"}) {
issue {
number
body
}
}
}
You can try both call in the graphql explorer and running first the FindRepo request and then CreateIssue
Or you can do it like this:
As the previous answer said, you have to find the repositoryId first, or you will met the error in the image.
And further more, when you have any issues finding a way to do mutation or query, you can find your answer in the Doc section in the right of the github explorer.

Building GraphQL services in isolation with apollo-federation

I'm currently trying to test 1 service's graphql endpoint that will eventually be apart of an apollo-federation/gateway graphql server. This service will extend a type in an existing service in the existing federated graph.
If I want to test my service in isolation with the apollo-federation & gateway, is there a way to do that while still using #extends and #external in my graphql schema? Currently the gateway throws: UnhandledPromiseRejectionWarning: Error: Unknown type: "SomeTypeInAnotherServer", which makes sense as there's no type to extend, but can I ignore this validation somehow?
as #xadm posted in a comment, you can achieve this with https://github.com/xolvio/federation-testing-tool which solves my problem.
Your question looks like you're trying to do development, but the answer you gave looks like you're specifically doing testing. I don't know if that's where you ended up because of tooling, or if that was your actual question, but this is the answer I have for people doing development:
If you're just running one of the services, you can still make queries against it, just do so in the way ApolloGateway would. Say for example, you have a person-service and a place-service, and People can visit many places:
Person Service
type Person #key(fields: "id") {
id: ID!
name: String
}
type Query {
person(id: ID): Person # Assuming this is the only entry-point
}
Place Service
type Place {
id: ID!
name: String
}
extend type Person #key(fields: "id") {
id: ID!
placesVisited: [Place]
}
Now you can make the following query to the place-service:
query ($_representations: [_Any!]!) {
_entities(representations:$_representations) {
... on Person {
id
placesVisited {
id
name
}
}
}
}
and here is your input:
{
"_representations": [{
"__typename": "Person",
"id": "some-id-of-some-person"
}]
}

Cannot perform update query because update values are not defined

I am trying to execute a mutation like so
mutation creating {
createTeam(
payload: {
name: "Team von abc"
tacts:["94b4cbc2-b996-482f-b712-967bdb646e73"]
}
) {
id
name
}
}
This results in :
"message": "Cannot perform update query because update values are not
defined. Call \"qb.set(...)\" method to specify updated values.",
My graphql is defined like this:
input CreateTeamPayload {
name: String
tacts:[ID!]
}
type Team {
id: ID!
name: String
tacts: [Tact]!
}
type Query {
fetchTeams: [Team]!
fetchTeamById(id: ID!): Team
}
type Mutation {
createTeam(payload: CreateTeamPayload): Team!
}
My Team requires an ID from a "tact" so I provide him with an ID from a "tact" I created before. Is this approach wrong? How can I mutate types that reference other types? is there some documentation that actually does this?

How to create a new entry in a specific collection?

Or in other words: How can I create a new entry that has a relationship with a specific collection and only with it?
The following code creates a new entry of the type Brand. How can I place it inside a specific collection?
I'm new to graphql, so if what I would like to achieve is not possible at all or not the way graphql works please tell me
Additional information:
I'm using mlab as my back end, and strapi (headless cms). On strapi I installed graphql as an external plugin.
Thanks in advance
mutation {
createBrand(input: {
data: {
name: "John",
description: "this is my description"
}
}) {
brand {
name
description
}
}
}
To my very limited understanding of graphql, I think that in order to associate a new entry with a specific collection you need to edit the code above and add:
mutation {
createBrand(input: {
data: {
name: "John",
description: "this is my description"
collectionInPlurals: ['collectionId']
}
}) {
brand {
name
description
}
}
}
collectioninPlurals for example could be items if the type of the collection is 'item' and then you provide the id of the specific item
I hope it could benefit others...

Resources