Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Mutation UpdateProjectV2ItemFieldValue fails with ProjectV2FieldValue has the wrong arguments error #292

Open
1 task done
CodyALohse opened this issue Feb 17, 2023 · 2 comments
Labels
hacktoberfest Issues for participation in Hacktoberfest Status: Up for grabs Issues that are ready to be worked on by anyone Type: Bug Something isn't working as documented

Comments

@CodyALohse
Copy link

What happened?

When performing an UpdateProjectV2ItemFieldValue mutation the response returns with a ProjectV2FieldValue has the wrong arguments error

var updateStatusQuery = new Mutation().UpdateProjectV2ItemFieldValue(
	new UpdateProjectV2ItemFieldValueInput {
		FieldId = new ID("xxxxxxx_xxxxxxx-xxxxxxxxxxxx"),
		ItemId = new ID("xxxxxx_xxxxxxxxx-xxxxxxxxxxxx"),
		ProjectId = new ID("xxx_xxxxxxx-xxxxxxx"),
		ClientMutationId = "abc123",
		Value = new ProjectV2FieldValue {
			SingleSelectOptionId = "8499aa9c" 
		}
	})
	.Select(p => p.ProjectV2Item.Id);
	
var updateStatusRes = await connection.Run(updateStatusQuery);

Below is the generated query:

{ "query":"mutation {
    updateProjectV2ItemFieldValue(input:{
        projectId:\"xxx_xxxxxxx-xxxxxxxs\",
        itemId:\"xxxxxx_xxxxxxxxx-xxxxxxxxxxxx\",
        fieldId:\"xxxxxxx_xxxxxxx-xxxxxxxxxxxx\",
        value:{
            text:null,
            number:null,
            date:null,
            singleSelectOptionId:\"8499aa9c\",
            iterationId:null }
        ,clientMutationId:\"abc123\"})
        {projectV2Item{id}}}","variables":null}

It appears that the value object ProjectV2FieldValue cannot be passed with more than one property per request. Performing a request without the additional null properties does succeed:

{ "query":"mutation {
    updateProjectV2ItemFieldValue(input:{
        projectId:\"xxx_xxxxxxx-xxxxxxxs\",
        itemId:\"xxxxxx_xxxxxxxxx-xxxxxxxxxxxx\",
        fieldId:\"xxxxxxx_xxxxxxx-xxxxxxxxxxxx\",
        value:{
            singleSelectOptionId:\"8499aa9c\",
         }
        ,clientMutationId:\"abc123\"})
        {projectV2Item{id}}}","variables":null}

Thanks

Versions

v0.2.0-beta

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@CodyALohse CodyALohse added Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented labels Feb 17, 2023
@kfcampbell kfcampbell added Priority: Normal Status: Up for grabs Issues that are ready to be worked on by anyone and removed Status: Triage This is being looked at and prioritized labels Feb 17, 2023
abock added a commit to abock/octokit.graphql.net that referenced this issue Apr 13, 2023
ProjectV2FieldValue must provide exactly one property at a time
per documentation:

> The values that can be used to update a field of an item inside a
> Project. Only 1 value can be updated at a time.
>
> https://docs.github.com/en/graphql/reference/input-objects#projectv2fieldvalue

Fix this by skipping the serialization of null-valued properties.

Fixes octokit#292
@nickfloyd nickfloyd added the hacktoberfest Issues for participation in Hacktoberfest label Sep 20, 2023
@Dan-Albrecht
Copy link

@nickfloyd, in true hacktoberfest spirit, I have a total hack-job of a fix for this. The problem is, it introduces a coupling from Octokit.GraphQL.Core ➡️Octokit.GraphQL. This is actually a circular dependency, so 💩.

QuerySerializer needs to know ProjectV2FieldValue is special. I suppose I could solve this by creating a new interface in Core, that I'd slap on to the ProjectV2FieldValue and have the serializer SerializeValue sniff for. Thoughts?

@PaulStanos
Copy link

In case others need a workaround for this, the Octokit.GraphQL.Connection class allows you to run a query from a string. OP doesn't mention it specifically, but that's what I assume they did to confirm it works without these null values.

Below is a basic example of how to do this for a 'single select' field, though this should work for other field types, just specify the proper field name when setting up the value. You may also need to tweak the output. In my case, I don't need anything back from the API, so I just get a throwaway value.

var productInformation = new ProductHeaderValue( "your_client_name_here", "x.x.x" );
var gitHubConnection = new Connection( productInformation, "your_PAT_here");
ID projectId = /*<retrieve this from another API call>*/;
ID itemId = /*<retrieve this from another API call>*/;
ID fieldId = /*<retrieve this from another API call>*/;
string singleSelectOptionId = <retrieve this from another API>;

string queryStr = $"{{ \"query\":\"mutation {{updateProjectV2ItemFieldValue(input:{{projectId:\\\"{projectId.Value}\\\", itemId:\\\"{itemId.Value}\\\", fieldId:\\\"{fieldId.Value}\\\", value:{{singleSelectOptionId:\\\"{singleSelectOptionId}\\\"}}, clientMutationId:null}}){{id: projectV2Item{{id}}}}}}\",\"variables\":null}}";
await gitHubConnection.Run( queryStr );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest Issues for participation in Hacktoberfest Status: Up for grabs Issues that are ready to be worked on by anyone Type: Bug Something isn't working as documented
Projects
Status: 🔥 Backlog
Development

No branches or pull requests

5 participants