Skip to content
This repository has been archived by the owner on Jul 17, 2020. It is now read-only.

Commit

Permalink
Fix to ensure added schema types have typeName prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
travis-r6s committed Jun 22, 2020
1 parent d11483e commit 145f06b
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 64 deletions.
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { promisify } = require('util')
const stream = require('stream')

const { PRODUCTS_QUERY, COLLECTIONS_QUERY } = require('./queries')
const { ProductSchema, SKUSchema, ImageSchema, SEOSchema, ProductMetadata, CollectionSchema, AttributeSchema } = require('./schema')
const createSchema = require('./schema')

const defaultTypes = {
PRODUCT: 'Product',
Expand Down Expand Up @@ -61,7 +61,7 @@ async function ElliotSource (api, options = {}) {
actions.addCollection(TYPENAMES.SKU)

// Setup Schema
actions.addSchemaTypes([ProductSchema, SKUSchema, ImageSchema, SEOSchema, ProductMetadata, CollectionSchema, AttributeSchema])
actions.addSchemaTypes(createSchema(typeName))

// Load Data
await loadCollections(actions)
Expand Down Expand Up @@ -119,7 +119,7 @@ async function ElliotSource (api, options = {}) {
return { image: localPath }
})

const attributes = product.attributes.map(({ attributeKey, attributeValues }) => ({ name: attributeKey, values: attributeValues, key: attributeKey.toLowerCase() }))
const attributes = Array.isArray(product.attributes) ? product.attributes.map(({ attributeKey, attributeValues }) => ({ name: attributeKey, values: attributeValues, key: attributeKey.toLowerCase() })) : []
const seo = product.productSeo.edges.map(({ node }) => node)[ 0 ]
const metadata = product.metadata.edges.map(({ node }) => node)
const customMetadata = product.customMetadata.edges.map(({ node }) => node)
Expand Down
122 changes: 61 additions & 61 deletions src/schema.js
Original file line number Diff line number Diff line change
@@ -1,125 +1,125 @@
// 'Custom' defined schemas, to make sure fields are always available in the Gridsome Schema, and to remove any admin-specific fields

const ProductSchema = `type Product implements Node {
const ProductSchema = typeName => `type ${typeName}Product implements Node {
id: ID
productChannel: String
archived: Boolean
createdOn: Date
modifiedOn: Date
stripeId: String
name: String
description: String
shortDescription: String
downloadUrl: String
gender: Int
unitOfWeight: Int
weight: Float
isTaxable: Boolean
htsCode: String
unitOfDimensions: Int
height: Float
width: Float
htsCode: String
isTaxable: Boolean
isVendor: Boolean
length: Float
modifiedOn: Date
name: String
productChannel: String
quantity: Int
shortDescription: String
slug: String
stripeId: String
type: Int
downloadUrl: String
archived: Boolean
skus: [Sku]
images: [Images]
seo: Seo
customMetadata: [CustomProductMetadata]
metadata: [ProductMetadata]
collections: [Collection]
isVendor: Boolean
attributes: [ProductAttribute]
quantity: Int
unitOfDimensions: Int
unitOfWeight: Int
variantCount: Int
related: [Product]
weight: Float
width: Float
seo: ${typeName}Seo
skus: [${typeName}Sku]
images: [${typeName}Images]
customMetadata: [${typeName}CustomProductMetadata]
metadata: [${typeName}ProductMetadata]
collections: [${typeName}Collection]
attributes: [${typeName}ProductAttribute]
related: [${typeName}Product]
}`

const SKUSchema = `type Sku implements Node {
const SKUSchema = typeName => `type ${typeName}Sku implements Node {
basePrice: Int
height: Float
id: ID
sku: String
length: Float
purchaseLimit: Int
basePrice: Int
salePrice: Int
sku: String
unitOfDimensions: Int
unitOfWeight: Int
url: String
weight: Float
unitOfDimensions: Int
height: Float
width: Float
length: Float
product: Product
url: String
image: Image
attributes: [SkuAttribute]
product: ${typeName}Product
attributes: [${typeName}SkuAttribute]
}`

const ImageSchema = `type Images {
const ImageSchema = typeName => `type ${typeName}Images {
image: Image
}`

const SEOSchema = `type Seo {
const SEOSchema = typeName => `type ${typeName}Seo {
title: String
description: String
}`

const ProductMetadata = `
type ProductMetadata {
const ProductMetadata = typeName => `
type ${typeName}ProductMetadata {
id: ID!
createdOn: Date!
modifiedOn: Date!
productCategoryTag1: String
productCategoryTag2: String
productCategoryTag3: String
productDominantColor1: String
productDominantColor2: String
productDominantColor3: String
productDominantColor4: String
productDominantColor5: String
productCategoryTag1: String
productCategoryTag2: String
productCategoryTag3: String
productHtsCode: String
}
type CustomProductMetadata {
type ${typeName}CustomProductMetadata {
name: String
value: String
type: CustomProductMetadataType
type: ${typeName}CustomProductMetadataType
}
enum CustomProductMetadataType {
TEXT_INPUT
TEXT_EDITOR
enum ${typeName}CustomProductMetadataType {
DATE_TIME
MEDIA
TEXT_EDITOR
TEXT_INPUT
}`

const CollectionSchema = `type Collection implements Node {
const CollectionSchema = typeName => `type ${typeName}Collection implements Node {
id: ID!
archived: Boolean!
createdOn: Date!
isAutogenerated: Boolean!
modifiedOn: Date!
name: String!
isAutogenerated: Boolean!
slug: String
products: [Product]
archived: Boolean!
tags: [String]
products: [${typeName}Product]
}`

const AttributeSchema = `
type ProductAttribute {
const AttributeSchema = typeName => `
type ${typeName}ProductAttribute {
key: String
name: String
values: [String]
}
type SkuAttribute {
type ${typeName}SkuAttribute {
key: String
name: String
value: String
}
`

module.exports = {
ProductSchema,
SKUSchema,
ImageSchema,
SEOSchema,
ProductMetadata,
CollectionSchema,
AttributeSchema
}
module.exports = typeName => [
ProductSchema(typeName),
SKUSchema(typeName),
ImageSchema(typeName),
SEOSchema(typeName),
ProductMetadata(typeName),
CollectionSchema(typeName),
AttributeSchema(typeName)
]

0 comments on commit 145f06b

Please sign in to comment.