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 · 4 comments · May be fixed by #319
Open
1 task done
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
@kfcampbell kfcampbell moved this from 🆕 Triage to 🔥 Backlog in 🧰 Octokit Active 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 );

@mikeminutillo mikeminutillo linked a pull request Jun 5, 2024 that will close this issue
4 tasks
@mikeminutillo
Copy link

Is it required to explicitly send null values anywhere in the API?

I see that it is asserted here but I'm not sure if that is verifying that it can serialize with a null property, or if it is explicitly verifying that the null gets serialized.

If it is not required, I have a raised a PR to skip them here #319

@awright18
Copy link

awright18 commented Aug 7, 2024

+1 for this, would like to see the #319 PR merged assuming it aligns with the correct version of the spec.

dlagerro added a commit to dlagerro/gh-migrate-project that referenced this issue Aug 13, 2024
…alue

When running the import I am getting:an error:
```
2024-08-09T16:27:38.959Z debug: Response: 200 OK - {"data":{"addProjectV2DraftIssue":{"projectItem":{"id":"PVTI_lADOABJSZ84AmAGazgRtVEU"}}}}
2024-08-09T16:27:38.959Z info: Created project item PVTI_lADOABJSZ84AmAGazgRtVEU based on source project item MDEzOlByb2plY3RWMkl0ZW0zNTA2
2024-08-09T16:27:38.959Z info: Setting field "Status" (1/1) on project item PVTI_lADOABJSZ84AmAGazgRtVEU...
2024-08-09T16:27:38.960Z debug: Request: POST https://api.github.com/graphql -
    mutation updateProjectItemFieldValue($projectId: ID!, $itemId: ID!, $fieldId: ID!, $value: ProjectV2FieldValue!) {
      updateProjectV2ItemFieldValue(input: { projectId: $projectId, itemId: $itemId, fieldId: $fieldId, value: $value }) {
        projectV2Item {
          id
        }
      }
    }

2024-08-09T16:27:39.645Z debug: Response: 200 OK - {"data":{"updateProjectV2ItemFieldValue":null},"errors":[{"path":["updateProjectV2ItemFieldValue"],"locations":[{"line":3,"column":7}],"message":"ProjectV2FieldValue has the wrong arguments"}]}
Request failed due to following response errors:
 - ProjectV2FieldValue has the wrong arguments
GraphqlResponseError: Request failed due to following response errors:
 - ProjectV2FieldValue has the wrong arguments
    at /snapshot/dist/migrate-project.cjs
    at async updateProjectItemFieldValue (/snapshot/dist/migrate-project.cjs)
    at async importProjectItem (/snapshot/dist/migrate-project.cjs)
    at async /snapshot/dist/migrate-project.cjs
    at async _Command.<anonymous> (/snapshot/dist/migrate-project.cjs)
```

Our hackathon project uses a singleSelectOptionId for the item's status field which
seems similar to this issue on the the dotnet graphql client:
octokit/octokit.graphql.net#292

Trying a similar fix here, remove the nulls from the value object before sending
it to github.
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

Successfully merging a pull request may close this issue.

7 participants