Skip to content

Commit

Permalink
fix(SLB-201): move gatsby directive autoloading entirely into schema …
Browse files Browse the repository at this point in the history
…package
  • Loading branch information
pmelab committed Jan 23, 2024
1 parent a922a77 commit 972dc30
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 71 deletions.
1 change: 0 additions & 1 deletion apps/website/gatsby-autoload.mjs

This file was deleted.

3 changes: 1 addition & 2 deletions apps/website/gatsby-config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
// pick it up instead of the JS file.

import { getPages } from '@custom/decap';
import autoload from '@custom/schema/gatsby-autoload';
import { resolve } from 'path';

import autoload from './gatsby-autoload.mjs';

const dir = resolve('node_modules/@custom/decap/data/page');

process.env.GATSBY_DRUPAL_URL =
Expand Down
3 changes: 1 addition & 2 deletions apps/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
"@amazeelabs/bridge-gatsby": "^1.2.7",
"@amazeelabs/cloudinary-responsive-image": "^1.6.15",
"@amazeelabs/gatsby-plugin-operations": "^1.1.3",
"@amazeelabs/gatsby-silverback-cloudinary": "^1.2.7",
"@amazeelabs/gatsby-source-silverback": "^1.13.10",
"@amazeelabs/gatsby-plugin-static-dirs": "workspace:*",
"@amazeelabs/gatsby-source-silverback": "^1.13.10",
"@amazeelabs/publisher": "^2.4.17",
"@amazeelabs/strangler-netlify": "^1.1.9",
"@custom/decap": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/schema/.graphqlrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://unpkg.com/[email protected]/config-schema.json",
"schema": [
"../../apps/website/node_modules/@amazeelabs/*/directives.graphql",
"node_modules/@amazeelabs/*/directives.graphql",
"../../apps/cms/web/modules/contrib/*/directives.graphql",
"../../apps/cms/web/modules/custom/*/directives.graphql",
"src/schema.graphql"
Expand Down
14 changes: 13 additions & 1 deletion packages/schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
],
"./operations": [
"./build/operations.json"
],
"./gatsby-autoload": [
"./build/gatsby-autoload.mjs"
]
},
"typesVersions": {
Expand All @@ -24,6 +27,9 @@
],
"/source": [
"build/generated/source.d.ts"
],
"gatsby-autoload": [
"src/types/gatsby-autoload.d.ts"
]
}
},
Expand All @@ -43,14 +49,20 @@
"@graphql-codegen/typescript-operations": "^4.0.1",
"@swc/cli": "^0.1.62",
"@swc/core": "^1.3.67",
"@types/image-size": "^0.8.0",
"@types/node": "^18",
"concurrently": "^8.2.2",
"graphql": "16.8.1",
"typescript": "^5.3.3"
},
"dependencies": {
"@amazeelabs/executors": "^1.1.0",
"@amazeelabs/gatsby-silverback-cloudinary": "^1.2.7",
"@amazeelabs/gatsby-source-silverback": "^1.13.10",
"@amazeelabs/scalars": "^1.6.13",
"@swc/cli": "^0.1.63",
"@swc/core": "^1.3.102"
"@swc/core": "^1.3.102",
"image-size": "^1.1.1",
"mime-types": "^2.1.35"
}
}
12 changes: 5 additions & 7 deletions apps/website/image.mjs → packages/schema/src/image.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import type { GraphQLFieldResolver } from 'graphql';
import sizeOf from 'image-size';
import mime from 'mime-types';
import { lookup } from 'mime-types';

/**
* @param {string | undefined} source
*/
export function imageProps(source) {
export const imageProps: GraphQLFieldResolver<string, any> = (source) => {
// If its a decap image, process it.
// Otherwise, it comes from Drupal and
// already has all necessary props.
Expand All @@ -20,8 +18,8 @@ export function imageProps(source) {
originalSrc: imageSrc,
width: dimensions.width || 0,
height: dimensions.height || 0,
mime: mime.lookup(relativeSource) || 'application/octet-stream',
mime: lookup(relativeSource) || 'application/octet-stream',
});
}
return source;
}
};
2 changes: 1 addition & 1 deletion packages/schema/src/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ scalar ImageSource @default @value(json: "\"\"")
Retrieve the properties of an image.
TODO: Move to a shared "image" package.
implementation(gatsby): ./image.mjs#imageProps
implementation(gatsby): ./image.js#imageProps
"""
directive @imageProps repeatable on FIELD_DEFINITION | SCALAR | UNION | ENUM | INTERFACE | OBJECT

Expand Down
3 changes: 3 additions & 0 deletions packages/schema/src/types/gatsby-autoload.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { GraphQLFieldResolver } from 'graphql';

export default Record<string, GraphQLFieldResolver<any, any>>;
File renamed without changes.
3 changes: 2 additions & 1 deletion packages/schema/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"forceConsistentCasingInFileNames": true,
"declaration": true,
"declarationDir": "build",
"outDir": "build"
"outDir": "build",
"lib": ["ES2015"]
},
"include": ["src"]
}
Loading

0 comments on commit 972dc30

Please sign in to comment.