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 40d8dd4 commit ad99642
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 68 deletions.
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
8 changes: 7 additions & 1 deletion packages/schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,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
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 ad99642

Please sign in to comment.