mghoneimy/php-graphql-client

Trying to produce mutation with nesting

jaseyd opened this issue · 1 comments

Hi there. I'm trying to produce the following mutation with this library:

mutation { purchaseOrders { accept ( poNumber: "TEST_94736163", shipSpeed: GROUND, lineItems: [ { partNumber: "JE10394E", quantity: 1, unitPrice: 9.99, estimatedShipDate: "2022-07-13 11:07:03.000000 -04:00" } ] ) { handle, submittedAt, errors { key, message } } } }

The additional layer accept is making it very difficult. At the moment I'm having to use the runRawQuery method in order to produce the above.

The closest I've come by using mutation with variables is this:

mutation($poNumber: String! $shipSpeed: ShipSpeed! $lineItems: AcceptedLineItemInput!) { purchaseOrders(poNumber: "TEST_94736163" shipSpeed: "GROUND" lineItems: ["test"]) }

However, the brackets are not in the right places.

I've seen the issue raised here but this does not help unfortunately.

If anyone has any ideas, please let me know.

Kind regards
Jason

Resolved this issue in the end. Marking as closed. Solution below for reference:

(new GraphQL\Mutation('purchaseOrders'))->setVariables([new \GraphQL\Variable('poNumber', 'String', true), new \GraphQL\Variable('shipSpeed', 'ShipSpeed', true), new \GraphQL\Variable('lineItems', '[AcceptedLineItemInput!]', true)])->setSelectionSet([(new \GraphQL\Query('accept'))->setArguments(['poNumber' => '$poNumber', 'shipSpeed' => '$shipSpeed', 'lineItems' => '$lineItems'])->setSelectionSet(['handle', 'submittedAt', (new \GraphQL\Query('errors'))->setSelectionSet(['key', 'message'])])])->__toString()