Skip to content

Commit

Permalink
Switch over to using our own query compiler for a smaller bundle size
Browse files Browse the repository at this point in the history
  • Loading branch information
airhorns committed Jul 24, 2023
1 parent 3bc67bb commit 0f2b044
Show file tree
Hide file tree
Showing 22 changed files with 1,611 additions and 309 deletions.
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ module.exports = {
"<rootDir>/packages/api-client-core/jest.config.js",
"<rootDir>/packages/react/jest.config.js",
"<rootDir>/packages/react-shopify-app-bridge/jest.config.js",
"<rootDir>/packages/tiny-graphql-query-compiler/jest.config.js",
],
};
3 changes: 2 additions & 1 deletion packages/api-client-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@opentelemetry/api": "^1.4.0",
"@urql/core": "^4.0.10",
"cross-fetch": "^3.1.5",
"gql-query-builder": "^3.7.2",
"tiny-graphql-query-compiler": "^0.1.0",
"graphql": "~16.6.0",
"graphql-ws": "^5.13.1",
"isomorphic-ws": "^5.0.0",
Expand All @@ -31,6 +31,7 @@
"ws": "^8.13.0"
},
"devDependencies": {
"tiny-graphql-query-compiler": "workspace:*",
"@types/lodash.clonedeep": "^4.5.6",
"@types/lodash.isequal": "^4.5.5",
"@types/node": "^14.18.26",
Expand Down
56 changes: 0 additions & 56 deletions packages/api-client-core/spec/FieldSelection.spec.ts

This file was deleted.

177 changes: 146 additions & 31 deletions packages/api-client-core/spec/InternalModelManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,23 @@ describe("InternalModelManager", () => {
const plan = internalFindManyQuery("widget", undefined);
expect(plan).toMatchInlineSnapshot(`
{
"query": "query InternalFindManyWidget ($after: String, $before: String, $first: Int, $last: Int) { internal { listWidget (after: $after, before: $before, first: $first, last: $last) { pageInfo { hasNextPage, hasPreviousPage, startCursor, endCursor }, edges { cursor, node } } } }",
"variables": {
"after": undefined,
"before": undefined,
"first": undefined,
"last": undefined,
},
"query": "query InternalFindManyWidget {
internal {
listWidget {
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
edges {
cursor
node
}
}
}
}",
"variables": {},
}
`);
expectValidGraphQLQuery(plan.query);
Expand All @@ -150,12 +160,23 @@ describe("InternalModelManager", () => {
const plan = internalFindManyQuery("widget", { sort: [{ id: "Ascending" }] });
expect(plan).toMatchInlineSnapshot(`
{
"query": "query InternalFindManyWidget ($sort: [WidgetSort!], $after: String, $before: String, $first: Int, $last: Int) { internal { listWidget (sort: $sort, after: $after, before: $before, first: $first, last: $last) { pageInfo { hasNextPage, hasPreviousPage, startCursor, endCursor }, edges { cursor, node } } } }",
"query": "query InternalFindManyWidget($sort: [WidgetSort!]) {
internal {
listWidget(sort: $sort) {
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
edges {
cursor
node
}
}
}
}",
"variables": {
"after": undefined,
"before": undefined,
"first": undefined,
"last": undefined,
"sort": [
{
"id": "Ascending",
Expand All @@ -171,12 +192,23 @@ describe("InternalModelManager", () => {
const plan = internalFindManyQuery("widget", { search: "term" });
expect(plan).toMatchInlineSnapshot(`
{
"query": "query InternalFindManyWidget ($search: String, $after: String, $before: String, $first: Int, $last: Int) { internal { listWidget (search: $search, after: $after, before: $before, first: $first, last: $last) { pageInfo { hasNextPage, hasPreviousPage, startCursor, endCursor }, edges { cursor, node } } } }",
"query": "query InternalFindManyWidget($search: String) {
internal {
listWidget(search: $search) {
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
edges {
cursor
node
}
}
}
}",
"variables": {
"after": undefined,
"before": undefined,
"first": undefined,
"last": undefined,
"search": "term",
},
}
Expand All @@ -188,19 +220,30 @@ describe("InternalModelManager", () => {
const plan = internalFindManyQuery("widget", { filter: [{ id: { equals: "1" } }] });
expect(plan).toMatchInlineSnapshot(`
{
"query": "query InternalFindManyWidget ($filter: [WidgetFilter!], $after: String, $before: String, $first: Int, $last: Int) { internal { listWidget (filter: $filter, after: $after, before: $before, first: $first, last: $last) { pageInfo { hasNextPage, hasPreviousPage, startCursor, endCursor }, edges { cursor, node } } } }",
"query": "query InternalFindManyWidget($filter: [WidgetFilter!]) {
internal {
listWidget(filter: $filter) {
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
edges {
cursor
node
}
}
}
}",
"variables": {
"after": undefined,
"before": undefined,
"filter": [
{
"id": {
"equals": "1",
},
},
],
"first": undefined,
"last": undefined,
},
}
`);
Expand All @@ -225,7 +268,15 @@ describe("InternalModelManager", () => {
const plan = internalFindFirstQuery("widget", undefined);
expect(plan).toMatchInlineSnapshot(`
{
"query": "query InternalFindFirstWidget ($first: Int) { internal { listWidget (first: $first) { edges { node } } } }",
"query": "query InternalFindFirstWidget($first: Int) {
internal {
listWidget(first: $first) {
edges {
node
}
}
}
}",
"variables": {
"first": 1,
},
Expand All @@ -238,7 +289,15 @@ describe("InternalModelManager", () => {
const plan = internalFindFirstQuery("widget", { sort: [{ id: "Ascending" }] });
expect(plan).toMatchInlineSnapshot(`
{
"query": "query InternalFindFirstWidget ($sort: [WidgetSort!], $first: Int) { internal { listWidget (sort: $sort, first: $first) { edges { node } } } }",
"query": "query InternalFindFirstWidget($sort: [WidgetSort!], $first: Int) {
internal {
listWidget(sort: $sort, first: $first) {
edges {
node
}
}
}
}",
"variables": {
"first": 1,
"sort": [
Expand All @@ -256,7 +315,15 @@ describe("InternalModelManager", () => {
const plan = internalFindFirstQuery("widget", { search: "term" });
expect(plan).toMatchInlineSnapshot(`
{
"query": "query InternalFindFirstWidget ($search: String, $first: Int) { internal { listWidget (search: $search, first: $first) { edges { node } } } }",
"query": "query InternalFindFirstWidget($search: String, $first: Int) {
internal {
listWidget(search: $search, first: $first) {
edges {
node
}
}
}
}",
"variables": {
"first": 1,
"search": "term",
Expand All @@ -270,7 +337,15 @@ describe("InternalModelManager", () => {
const plan = internalFindFirstQuery("widget", { filter: [{ id: { equals: "1" } }] });
expect(plan).toMatchInlineSnapshot(`
{
"query": "query InternalFindFirstWidget ($filter: [WidgetFilter!], $first: Int) { internal { listWidget (filter: $filter, first: $first) { edges { node } } } }",
"query": "query InternalFindFirstWidget($filter: [WidgetFilter!], $first: Int) {
internal {
listWidget(filter: $filter, first: $first) {
edges {
node
}
}
}
}",
"variables": {
"filter": [
{
Expand All @@ -291,7 +366,15 @@ describe("InternalModelManager", () => {
expect(plan.variables.select).toEqual(["foo", "bar"]);
expect(plan).toMatchInlineSnapshot(`
{
"query": "query InternalFindFirstWidget ($select: [String!], $first: Int) { internal { listWidget (select: $select, first: $first) { edges { node } } } }",
"query": "query InternalFindFirstWidget($select: [String!], $first: Int) {
internal {
listWidget(select: $select, first: $first) {
edges {
node
}
}
}
}",
"variables": {
"first": 1,
"select": [
Expand All @@ -310,7 +393,15 @@ describe("InternalModelManager", () => {
const plan = internalFindFirstQuery("widget_model", undefined);
expect(plan).toMatchInlineSnapshot(`
{
"query": "query InternalFindFirstWidgetModel ($first: Int) { internal { listWidgetModel (first: $first) { edges { node } } } }",
"query": "query InternalFindFirstWidgetModel($first: Int) {
internal {
listWidgetModel(first: $first) {
edges {
node
}
}
}
}",
"variables": {
"first": 1,
},
Expand All @@ -323,7 +414,15 @@ describe("InternalModelManager", () => {
const plan = internalFindFirstQuery("widget_model", { sort: [{ id: "Ascending" }] });
expect(plan).toMatchInlineSnapshot(`
{
"query": "query InternalFindFirstWidgetModel ($sort: [WidgetModelSort!], $first: Int) { internal { listWidgetModel (sort: $sort, first: $first) { edges { node } } } }",
"query": "query InternalFindFirstWidgetModel($sort: [WidgetModelSort!], $first: Int) {
internal {
listWidgetModel(sort: $sort, first: $first) {
edges {
node
}
}
}
}",
"variables": {
"first": 1,
"sort": [
Expand All @@ -341,7 +440,15 @@ describe("InternalModelManager", () => {
const plan = internalFindFirstQuery("widget_model", { search: "term" });
expect(plan).toMatchInlineSnapshot(`
{
"query": "query InternalFindFirstWidgetModel ($search: String, $first: Int) { internal { listWidgetModel (search: $search, first: $first) { edges { node } } } }",
"query": "query InternalFindFirstWidgetModel($search: String, $first: Int) {
internal {
listWidgetModel(search: $search, first: $first) {
edges {
node
}
}
}
}",
"variables": {
"first": 1,
"search": "term",
Expand All @@ -355,7 +462,15 @@ describe("InternalModelManager", () => {
const plan = internalFindFirstQuery("widget_model", { filter: [{ id: { equals: "1" } }] });
expect(plan).toMatchInlineSnapshot(`
{
"query": "query InternalFindFirstWidgetModel ($filter: [WidgetModelFilter!], $first: Int) { internal { listWidgetModel (filter: $filter, first: $first) { edges { node } } } }",
"query": "query InternalFindFirstWidgetModel($filter: [WidgetModelFilter!], $first: Int) {
internal {
listWidgetModel(filter: $filter, first: $first) {
edges {
node
}
}
}
}",
"variables": {
"filter": [
{
Expand Down
Loading

0 comments on commit 0f2b044

Please sign in to comment.