diff --git a/packages/api/src/__generated__/schema.ts b/packages/api/src/__generated__/schema.ts index 715fbff712..2797d26258 100644 --- a/packages/api/src/__generated__/schema.ts +++ b/packages/api/src/__generated__/schema.ts @@ -75,7 +75,7 @@ export type Query = { allCollections: StoreCollectionConnection; allProducts: StoreProductConnection; collection: StoreCollection; - person: StorePerson; + person?: Maybe; product: StoreProduct; search: StoreSearchResult; }; diff --git a/packages/api/src/platforms/vtex/resolvers/query.ts b/packages/api/src/platforms/vtex/resolvers/query.ts index b5ba8b68ea..2315b5e045 100644 --- a/packages/api/src/platforms/vtex/resolvers/query.ts +++ b/packages/api/src/platforms/vtex/resolvers/query.ts @@ -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 ?? '', + } + ) }, } diff --git a/packages/api/src/typeDefs/index.ts b/packages/api/src/typeDefs/index.ts index f441dbaea6..57a1c75e77 100644 --- a/packages/api/src/typeDefs/index.ts +++ b/packages/api/src/typeDefs/index.ts @@ -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, @@ -44,6 +45,7 @@ export const typeDefs = [ Cart, Status, PropertyValue, + Person, ] .map(print) .join('\n') diff --git a/packages/api/src/typeDefs/person.graphql b/packages/api/src/typeDefs/person.graphql new file mode 100644 index 0000000000..54474249f7 --- /dev/null +++ b/packages/api/src/typeDefs/person.graphql @@ -0,0 +1,6 @@ +type StorePerson { + id: String! + email: String! + givenName: String! + familyName: String! +} diff --git a/packages/api/src/typeDefs/query.graphql b/packages/api/src/typeDefs/query.graphql index bd7f724244..b6fcb3dfc8 100644 --- a/packages/api/src/typeDefs/query.graphql +++ b/packages/api/src/typeDefs/query.graphql @@ -44,13 +44,6 @@ type StoreSearchResult { facets: [StoreFacet!]! } -type StorePerson { - id: String! - email: String! - givenName: String! - familyName: String! -} - type Query { product(locator: [IStoreSelectedFacet!]!): StoreProduct! @@ -68,5 +61,5 @@ type Query { allCollections(first: Int!, after: String): StoreCollectionConnection! - person: StorePerson! + person: StorePerson }