Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving session from query to resolver
- Loading branch information
1 parent
2a80fcb
commit 2fb1863
Showing
6 changed files
with
41 additions
and
38 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import { validateCart } from './validateCart' | ||
import session from './session' | ||
|
||
export const Mutation = { | ||
validateCart, | ||
session, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { Context } from '..' | ||
import type { MutationSessionArgs } from '../../../__generated__/schema' | ||
import ChannelParser from '../utils/channel' | ||
|
||
export default async function sessionResolvers( | ||
_: any, | ||
{ session }: MutationSessionArgs, | ||
{ clients }: Context | ||
) { | ||
const channelParser = new ChannelParser(session?.channel ?? '') | ||
const regionData = await clients.commerce.checkout.region({ | ||
postalCode: String(session.postalCode ?? '').replace(/\D/g, ''), | ||
country: session.country ?? '', | ||
}) | ||
|
||
channelParser.updateChannel({ regionId: regionData?.[0]?.id }) | ||
|
||
return { ...session, channel: channelParser.stringify() } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,18 @@ | ||
type StoreSession { | ||
channel: String | ||
country: String | ||
postalCode: String | ||
} | ||
|
||
input IStoreSession { | ||
channel: String | ||
country: String | ||
postalCode: String | ||
} | ||
|
||
type Mutation { | ||
# Returns the order if anything changed with the order. Null if the order is valid | ||
validateCart(cart: IStoreCart!): StoreCart | ||
|
||
session(session: IStoreSession!): StoreSession! | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters