Skip to content

Commit

Permalink
Mutation response (#879)
Browse files Browse the repository at this point in the history
* make MutationStore.mutation return full payload

* release guide

* changeset
  • Loading branch information
AlecAivazis authored Feb 1, 2023
1 parent 4a215be commit ab96b1c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/cool-panthers-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'houdini-svelte': major
---

MutationStore.mutate returns full payload
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
</form>

<div id="result">
{form?.addUser?.name || 'No user added'}
{form?.data?.addUser?.name || 'No user added'}
</div>
24 changes: 11 additions & 13 deletions packages/houdini-svelte/src/runtime/stores/mutation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { DocumentStore } from '$houdini/runtime/client'
import type { MutationArtifact, GraphQLObject } from '$houdini/runtime/lib/types'
import type { MutationArtifact, GraphQLObject, QueryResult } from '$houdini/runtime/lib/types'
import type { RequestEvent } from '@sveltejs/kit'

import { initClient } from '../client'
Expand All @@ -26,7 +26,7 @@ export class MutationStore<
fetch?: typeof globalThis.fetch
event?: RequestEvent
} & MutationConfig<_Data, _Input, _Optimistic> = {}
): Promise<_Data> {
): Promise<QueryResult<_Data, _Input>> {
await initClient()

const { context } = await fetchParams(this.artifact, this.artifact.name, {
Expand All @@ -35,17 +35,15 @@ export class MutationStore<
event,
})

return (
await this.observer.send({
variables,
fetch: context.fetch,
metadata,
session: context.session,
stuff: {
...mutationConfig,
},
})
).data!
return await this.observer.send({
variables,
fetch: context.fetch,
metadata,
session: context.session,
stuff: {
...mutationConfig,
},
})
}

subscribe(...args: Parameters<DocumentStore<_Data, _Input>['subscribe']>) {
Expand Down
23 changes: 23 additions & 0 deletions site/src/routes/guides/release-notes/+page.svx
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,29 @@ need to pass a new config to your client:

</DeepDive>

### Mutation return value changed

Because of the change in Houdini's default error handling, mutations were brought
in line with query behavior and return the full query result with `data`, `errors`,
etc.

```diff:title=src/components/AddFriend.svelte
<script>
const mutation = graphql(`
mutation AddFriend {
addFriend {
...
}
}
`)

async function onClick() {
- const { addFriend } = await mutation.mutate()
+ const { data: { addFriend } } = await mutation.mutate()
}
</script>
```

### Grouped `apiUrl`, `schemaPollHeaders`, and `schemaPollInterval` together

In order to clarify the difference between the `apiUrl` config value and the
Expand Down

0 comments on commit ab96b1c

Please sign in to comment.