-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b7b540
commit 937bbec
Showing
12 changed files
with
15,808 additions
and
209 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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
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
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,3 +1,3 @@ | ||
import getProducts from './get-products.js'; | ||
|
||
export default {getProducts}; | ||
export default { getProducts }; |
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,25 +1,40 @@ | ||
import shopify from '../../shopify.js'; | ||
import { GET_FDC_PRODUCTS_QUERY } from './queries/GET_FDC_PRODUCTS_QUERY.js'; | ||
/* eslint-disable no-shadow */ | ||
/* eslint-disable arrow-body-style */ | ||
/* eslint-disable import/prefer-default-export */ | ||
/* eslint-disable max-len */ | ||
import { getFDCProductGraphQlQuery } from './queries/GET_FDC_PRODUCTS_QUERY.js'; | ||
import getClient from './get-client.js'; | ||
|
||
// get only products that have fdc inside tags | ||
// this query works only for the first 10 products, we should loop through all products and get the ones that have fdc inside tags | ||
export const getProducts = async ({ session }) => { | ||
export const getProducts = async ({ | ||
session, | ||
nextPageCursor, | ||
previousPageCursor | ||
}) => { | ||
const client = getClient(session); | ||
|
||
try { | ||
const products = await client.query({ | ||
data: GET_FDC_PRODUCTS_QUERY | ||
data: getFDCProductGraphQlQuery({ | ||
nextPageCursor, | ||
previousPageCursor | ||
}) | ||
}); | ||
|
||
return products.body.data.products.edges.map(({ node }) => { | ||
return { | ||
...node, | ||
variants: node.variants.edges.map(({ node }) => node) | ||
}; | ||
}); | ||
return { | ||
pageInfo: products.body.data.products.pageInfo, | ||
list: products.body.data.products.edges.map(({ node }) => { | ||
return { | ||
...node, | ||
variants: { | ||
hasNextPage: node.variants.pageInfo.hasNextPage, | ||
list: node.variants.edges.map(({ node }) => node) | ||
} | ||
}; | ||
}) | ||
}; | ||
} catch (e) { | ||
console.error('eee', JSON.stringify(e, null, 2)); | ||
throw e; | ||
throw new Error(e); | ||
} | ||
}; |
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
74 changes: 43 additions & 31 deletions
74
web/fdc-repositories/shopify/queries/GET_FDC_PRODUCTS_QUERY.js
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,38 +1,50 @@ | ||
// The max first value is 250 | ||
export const GET_FDC_PRODUCTS_QUERY = `{ | ||
products(first: 10, after: null, before: null) { | ||
pageInfo { | ||
hasNextPage | ||
hasPreviousPage | ||
endCursor | ||
startCursor | ||
} | ||
edges { | ||
cursor | ||
node { | ||
id | ||
title | ||
description | ||
variants(first: 5) { | ||
pageInfo { | ||
hasNextPage | ||
hasPreviousPage | ||
endCursor | ||
startCursor | ||
} | ||
edges { | ||
node { | ||
id | ||
title | ||
inventoryItem { | ||
/* eslint-disable import/prefer-default-export */ | ||
|
||
export const getFDCProductGraphQlQuery = ({ | ||
nextPageCursor = 'null', | ||
previousPageCursor = 'null' | ||
}) => { | ||
const after = nextPageCursor === 'null' ? '' : `after: "${nextPageCursor}"`; | ||
const before = | ||
previousPageCursor === 'null' ? '' : `before: "${previousPageCursor}"`; | ||
|
||
return `{ | ||
products(first: 5, ${after}, ${before} ,query:"tag:fdc") { | ||
pageInfo { | ||
hasNextPage | ||
hasPreviousPage | ||
endCursor | ||
startCursor | ||
} | ||
edges { | ||
cursor | ||
node { | ||
id | ||
handle | ||
title | ||
description | ||
variants(first: 10) { | ||
pageInfo { | ||
hasNextPage | ||
hasPreviousPage | ||
endCursor | ||
startCursor | ||
} | ||
edges { | ||
node { | ||
id | ||
title | ||
price | ||
inventoryItem { | ||
id | ||
} | ||
inventoryPolicy | ||
availableForSale | ||
} | ||
inventoryPolicy | ||
availableForSale | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}`; | ||
}`; | ||
}; |
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
Oops, something went wrong.