Skip to content

Commit

Permalink
return null when there is no profile
Browse files Browse the repository at this point in the history
  • Loading branch information
tlgimenes committed Mar 24, 2022
1 parent 7e8b039 commit a9a8607
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/api/src/__generated__/schema.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 9 additions & 7 deletions packages/api/src/platforms/vtex/resolvers/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,16 @@ export const Query = {
} = ctx

const {
namespaces: { profile },
namespaces: { profile = null },
} = await commerce.session()

return {
id: profile?.id?.value ?? '',
email: profile?.email?.value ?? '',
givenName: profile?.firstName?.value ?? '',
familyName: profile?.lastName?.value ?? '',
}
return (
profile && {
id: profile.id,
email: profile.email?.value ?? '',
givenName: profile.firstName?.value ?? '',
familyName: profile.lastName?.value ?? '',
}
)
},
}
2 changes: 2 additions & 0 deletions packages/api/src/typeDefs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Seo from './seo.graphql'
import Cart from './cart.graphql'
import Status from './status.graphql'
import PropertyValue from './propertyValue.graphql'
import Person from './person.graphql'

export const typeDefs = [
Query,
Expand All @@ -44,6 +45,7 @@ export const typeDefs = [
Cart,
Status,
PropertyValue,
Person,
]
.map(print)
.join('\n')
6 changes: 6 additions & 0 deletions packages/api/src/typeDefs/person.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type StorePerson {
id: String!
email: String!
givenName: String!
familyName: String!
}
9 changes: 1 addition & 8 deletions packages/api/src/typeDefs/query.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ type StoreSearchResult {
facets: [StoreFacet!]!
}

type StorePerson {
id: String!
email: String!
givenName: String!
familyName: String!
}

type Query {
product(locator: [IStoreSelectedFacet!]!): StoreProduct!

Expand All @@ -68,5 +61,5 @@ type Query {

allCollections(first: Int!, after: String): StoreCollectionConnection!

person: StorePerson!
person: StorePerson
}

0 comments on commit a9a8607

Please sign in to comment.