graphile-build
Advanced tools
Comparing version 5.0.0-beta.5 to 5.0.0-beta.6
# graphile-build | ||
## 5.0.0-beta.6 | ||
### Patch Changes | ||
- [#488](https://github.com/benjie/crystal/pull/488) | ||
[`73f1b5218`](https://github.com/benjie/crystal/commit/73f1b52187b2e009d502afa1db8a4e8f702e2958) | ||
Thanks [@benjie](https://github.com/benjie)! - specForHandler now only | ||
requires handler - no need to pass codec. | ||
- Updated dependencies | ||
[[`53186213a`](https://github.com/benjie/crystal/commit/53186213ade962f4b66cb0d5ea8b57b5ce7ea85f)]: | ||
- grafast@0.0.1-beta.5 | ||
## 5.0.0-beta.5 | ||
@@ -4,0 +17,0 @@ |
@@ -174,3 +174,3 @@ import type { BaseGraphQLArguments, ExecutableStep, GrafastArgumentConfig, GrafastFieldConfig, GrafastFieldConfigArgumentMap, GrafastInputFieldConfig, GrafastInputFieldConfigMap, OutputPlanForType } from "grafast"; | ||
* Inflection controls the naming of your fields, types, arguments, etc - | ||
* use it widely! | ||
* widely used for any situation where you need to name things. Use it often! | ||
*/ | ||
@@ -238,2 +238,3 @@ inflection: Inflection; | ||
} | null; | ||
specGenerator: (() => Omit<GraphileBuild.GrafastObjectTypeConfig<any, any>, "name">) | (() => Omit<GrafastInterfaceTypeConfig<any, any>, "name">) | (() => Omit<GrafastUnionTypeConfig<any, any>, "name">) | (() => Omit<GraphQLScalarTypeConfig<any, any>, "name">) | (() => Omit<GraphQLEnumTypeConfig, "name">) | (() => Omit<GrafastInputObjectTypeConfig, "name">); | ||
} | null; | ||
@@ -240,0 +241,0 @@ /** |
@@ -13,2 +13,3 @@ "use strict"; | ||
const version_js_1 = require("./version.js"); | ||
const BUILTINS = ["Int", "Float", "Boolean", "ID", "String"]; | ||
/** Have we warned the user they're using the 5-arg deprecated registerObjectType call? */ | ||
@@ -61,2 +62,3 @@ let registerObjectType5argsDeprecatedWarned = false; | ||
typeRegistry[typeName] = { | ||
typeName, | ||
klass, | ||
@@ -191,2 +193,19 @@ scope, | ||
origin: "GraphQL builtin", | ||
specGenerator: () => { | ||
switch (typeName) { | ||
case "String": | ||
return graphql_1.GraphQLString.toConfig(); | ||
case "ID": | ||
return graphql_1.GraphQLID.toConfig(); | ||
case "Boolean": | ||
return graphql_1.GraphQLBoolean.toConfig(); | ||
case "Int": | ||
return graphql_1.GraphQLInt.toConfig(); | ||
case "Float": | ||
return graphql_1.GraphQLFloat.toConfig(); | ||
default: { | ||
throw new Error(`Unhandled built-in '${typeName}'`); | ||
} | ||
} | ||
}, | ||
}); | ||
@@ -196,3 +215,3 @@ } | ||
if (details != null) { | ||
const { klass: Constructor, scope, origin } = details; | ||
const { klass: Constructor, scope, origin, specGenerator } = details; | ||
return Object.assign(Object.create(null), { | ||
@@ -202,2 +221,3 @@ Constructor, | ||
origin, | ||
specGenerator, | ||
}); | ||
@@ -208,2 +228,10 @@ } | ||
getTypeByName(typeName) { | ||
if (currentTypeDetails && !BUILTINS.includes(typeName)) { | ||
throw new Error(`Error in spec callback for ${currentTypeDetails.klass.name} '${currentTypeDetails.typeName}'; the callback made a call to \`build.getTypeByName(${JSON.stringify(typeName)})\` (directly or indirectly) - this is the wrong time for such a call \ | ||
to occur since it can lead to circular dependence. To fix this, ensure that any \ | ||
calls to \`getTypeByName\` can only occur inside of the callbacks, such as \ | ||
\`fields()\`, \`interfaces()\`, \`types()\` or similar. Be sure to use the callback \ | ||
style for these configuration options (e.g. change \`interfaces: \ | ||
[getTypeByName('Foo')]\` to \`interfaces: () => [getTypeByName('Foo')]\``); | ||
} | ||
if (!this.status.isInitPhaseComplete) { | ||
@@ -216,3 +244,5 @@ throw new Error("Must not call build.getTypeByName before 'init' phase is complete"); | ||
else if (building.has(typeName)) { | ||
throw new Error(`Construction cycle detected: ${typeName} is already being built. Most likely this means that you forgot to use a callback for 'fields', 'interfaces', 'types', etc. when defining a type.`); | ||
throw new Error(`Construction cycle detected: ${typeName} is already being built (build stack: ${[ | ||
...building, | ||
].join(">")}). Most likely this means that you forgot to use a callback for 'fields', 'interfaces', 'types', etc. when defining a type.`); | ||
} | ||
@@ -224,4 +254,4 @@ else { | ||
if (details != null) { | ||
const { klass, scope, specGenerator } = details; | ||
const spec = specGenerator(); | ||
const { klass, scope } = details; | ||
const spec = generateSpecFromDetails(details); | ||
// No need to have the user specify name, and they're forbidden from | ||
@@ -307,2 +337,12 @@ // changing name (use inflection instead!) so we just set it | ||
exports.default = makeNewBuild; | ||
let currentTypeDetails = null; | ||
function generateSpecFromDetails(details) { | ||
currentTypeDetails = details; | ||
try { | ||
return details.specGenerator(); | ||
} | ||
finally { | ||
currentTypeDetails = null; | ||
} | ||
} | ||
//# sourceMappingURL=makeNewBuild.js.map |
@@ -71,38 +71,40 @@ "use strict"; | ||
}, () => { | ||
const NodeType = build.getOutputTypeByName(typeName); | ||
const EdgeType = build.getOutputTypeByName(edgeTypeName); | ||
const PageInfo = build.getOutputTypeByName(build.inflection.builtin("PageInfo")); | ||
return { | ||
assertStep: grafast_1.ConnectionStep, | ||
description: build.wrapDescription(`A connection to a list of \`${typeName}\` values.`, "type"), | ||
fields: ({ fieldWithHooks }) => ({ | ||
nodes: fieldWithHooks({ | ||
fieldName: "nodes", | ||
}, () => ({ | ||
description: build.wrapDescription(`A list of \`${typeName}\` objects.`, "field"), | ||
type: new build.graphql.GraphQLNonNull(new build.graphql.GraphQLList(nullableIf(!nonNullNode, NodeType))), | ||
plan: (0, utils_js_1.EXPORTABLE)(() => function plan($connection) { | ||
return $connection.nodes(); | ||
}, []), | ||
})), | ||
edges: fieldWithHooks({ | ||
fieldName: "edges", | ||
}, () => ({ | ||
description: build.wrapDescription(`A list of edges which contains the \`${typeName}\` and cursor to aid in pagination.`, "field"), | ||
type: nullableIf(false, new build.graphql.GraphQLList(nullableIf(!nonNullNode, EdgeType))), | ||
plan: (0, utils_js_1.EXPORTABLE)(() => function plan($connection) { | ||
return $connection.edges(); | ||
}, []), | ||
})), | ||
pageInfo: fieldWithHooks({ | ||
fieldName: "pageInfo", | ||
}, () => ({ | ||
description: build.wrapDescription("Information to aid in pagination.", "field"), | ||
type: new build.graphql.GraphQLNonNull(PageInfo), | ||
plan: (0, utils_js_1.EXPORTABLE)(() => function plan($connection) { | ||
// TYPES: why is this a TypeScript issue without the 'any'? | ||
return $connection.pageInfo(); | ||
}, []), | ||
})), | ||
}), | ||
fields: ({ fieldWithHooks }) => { | ||
const NodeType = build.getOutputTypeByName(typeName); | ||
const EdgeType = build.getOutputTypeByName(edgeTypeName); | ||
const PageInfo = build.getOutputTypeByName(build.inflection.builtin("PageInfo")); | ||
return { | ||
nodes: fieldWithHooks({ | ||
fieldName: "nodes", | ||
}, () => ({ | ||
description: build.wrapDescription(`A list of \`${typeName}\` objects.`, "field"), | ||
type: new build.graphql.GraphQLNonNull(new build.graphql.GraphQLList(nullableIf(!nonNullNode, NodeType))), | ||
plan: (0, utils_js_1.EXPORTABLE)(() => function plan($connection) { | ||
return $connection.nodes(); | ||
}, []), | ||
})), | ||
edges: fieldWithHooks({ | ||
fieldName: "edges", | ||
}, () => ({ | ||
description: build.wrapDescription(`A list of edges which contains the \`${typeName}\` and cursor to aid in pagination.`, "field"), | ||
type: nullableIf(false, new build.graphql.GraphQLList(nullableIf(!nonNullNode, EdgeType))), | ||
plan: (0, utils_js_1.EXPORTABLE)(() => function plan($connection) { | ||
return $connection.edges(); | ||
}, []), | ||
})), | ||
pageInfo: fieldWithHooks({ | ||
fieldName: "pageInfo", | ||
}, () => ({ | ||
description: build.wrapDescription("Information to aid in pagination.", "field"), | ||
type: new build.graphql.GraphQLNonNull(PageInfo), | ||
plan: (0, utils_js_1.EXPORTABLE)(() => function plan($connection) { | ||
// TYPES: why is this a TypeScript issue without the 'any'? | ||
return $connection.pageInfo(); | ||
}, []), | ||
})), | ||
}; | ||
}, | ||
}; | ||
@@ -109,0 +111,0 @@ }, `ConnectionPlugin connection type for ${typeName}`); |
import "graphile-config"; | ||
import type { ExecutableStep, NodeIdCodec, NodeIdHandler } from "grafast"; | ||
type NodeFetcher = { | ||
($nodeId: ExecutableStep<string>): ExecutableStep<any>; | ||
deprecationReason?: string; | ||
}; | ||
import type { ExecutableStep, NodeIdHandler } from "grafast"; | ||
declare global { | ||
namespace GraphileBuild { | ||
type NodeFetcher = { | ||
($nodeId: ExecutableStep<string>): ExecutableStep<any>; | ||
deprecationReason?: string; | ||
}; | ||
interface Build { | ||
specForHandler?(handler: NodeIdHandler, codec: NodeIdCodec): (nodeId: string) => any; | ||
specForHandler?(handler: NodeIdHandler): (nodeId: string) => any; | ||
nodeFetcherByTypeName?(typeName: string): NodeFetcher | null; | ||
@@ -22,3 +22,2 @@ } | ||
export declare const NodeAccessorPlugin: GraphileConfig.Plugin; | ||
export {}; | ||
//# sourceMappingURL=NodeAccessorPlugin.d.ts.map |
@@ -24,3 +24,3 @@ "use strict"; | ||
return build.extend(build, { | ||
specForHandler: (0, utils_js_1.EXPORTABLE)(() => function (handler, codec) { | ||
specForHandler: (0, utils_js_1.EXPORTABLE)(() => function (handler) { | ||
function spec(nodeId) { | ||
@@ -30,3 +30,3 @@ // We only want to return the specifier if it matches | ||
try { | ||
const specifier = codec.decode(nodeId); | ||
const specifier = handler.codec.decode(nodeId); | ||
if (handler.match(specifier)) { | ||
@@ -56,6 +56,5 @@ return specifier; | ||
return null; | ||
const codec = finalBuild.getNodeIdCodec(handler.codec.name); | ||
const fetcher = (0, utils_js_1.EXPORTABLE)((codec, handler, lambda, specForHandler) => { | ||
const fetcher = (0, utils_js_1.EXPORTABLE)((handler, lambda, specForHandler) => { | ||
const fn = ($nodeId) => { | ||
const $decoded = lambda($nodeId, specForHandler(handler, codec)); | ||
const $decoded = lambda($nodeId, specForHandler(handler)); | ||
return handler.get(handler.getSpec($decoded)); | ||
@@ -65,3 +64,3 @@ }; | ||
return fn; | ||
}, [codec, handler, grafast_1.lambda, specForHandler]); | ||
}, [handler, grafast_1.lambda, specForHandler]); | ||
nodeFetcherByTypeNameCache.set(typeName, fetcher); | ||
@@ -68,0 +67,0 @@ return fetcher; |
@@ -1,2 +0,2 @@ | ||
export declare const version = "5.0.0-beta.5"; | ||
export declare const version = "5.0.0-beta.6"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -5,3 +5,3 @@ "use strict"; | ||
// This file is autogenerated by /scripts/postversion.mjs | ||
exports.version = "5.0.0-beta.5"; | ||
exports.version = "5.0.0-beta.6"; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "graphile-build", | ||
"version": "5.0.0-beta.5", | ||
"version": "5.0.0-beta.6", | ||
"description": "Build a GraphQL schema from plugins", | ||
@@ -55,3 +55,3 @@ "type": "commonjs", | ||
"peerDependencies": { | ||
"grafast": "^0.0.1-beta.4", | ||
"grafast": "^0.0.1-beta.5", | ||
"graphile-config": "^0.0.1-beta.1", | ||
@@ -58,0 +58,0 @@ "graphql": "^16.1.0-experimental-stream-defer.6" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
443019
5090