Add options to duct-tape-compiler to control what gets emitted
This commit is contained in:
Родитель
0d7803caa6
Коммит
9643e3b4a7
|
@ -15,7 +15,7 @@
|
|||
"start": "yarn generate-resolver-typings && concurrently 'yarn duct-tape-compiler --watch' 'yarn serve'",
|
||||
"serve": "webpack serve",
|
||||
"build": "webpack",
|
||||
"duct-tape-compiler": "duct-tape-compiler --schema ./data/schema.graphql --src ./src --printWatchQueries",
|
||||
"duct-tape-compiler": "duct-tape-compiler --schema ./data/schema.graphql --src ./src --emitQueryDebugComments",
|
||||
"generate-resolver-typings": "graphql-codegen --config codegen.yml"
|
||||
},
|
||||
"eslintConfig": {
|
||||
|
@ -48,7 +48,6 @@
|
|||
"@welldone-software/why-did-you-render": "^6.2.1",
|
||||
"concurrently": "^6.2.1",
|
||||
"graphql-relay": "^0.10.0",
|
||||
"relay-compiler": "^10",
|
||||
"ts-loader": "9.3.1",
|
||||
"ts-node": "^10.2.1",
|
||||
"typescript": "4.7.4",
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
;
|
||||
|
||||
import { FragmentRefs } from "@graphitation/apollo-react-relay-duct-tape";
|
||||
export type AppQueryVariables = {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
;
|
||||
|
||||
import { FragmentRefs } from "@graphitation/apollo-react-relay-duct-tape";
|
||||
export type TodoListFooter_todosFragment = {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
;
|
||||
|
||||
/*
|
||||
query TodoListFooter_todosWatchNodeQuery($id: ID!) {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
;
|
||||
|
||||
import { FragmentRefs } from "@graphitation/apollo-react-relay-duct-tape";
|
||||
export type TodoListPaginationQueryVariables = {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
;
|
||||
|
||||
import { FragmentRefs } from "@graphitation/apollo-react-relay-duct-tape";
|
||||
export type TodoList_queryFragment = {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
;
|
||||
|
||||
import { FragmentRefs } from "@graphitation/apollo-react-relay-duct-tape";
|
||||
export type TodoRefetchQueryVariables = {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
;
|
||||
|
||||
import { FragmentRefs } from "@graphitation/apollo-react-relay-duct-tape";
|
||||
export type Todo_todoFragment = {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
;
|
||||
|
||||
export type AddTodoInput = {
|
||||
description: string;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
;
|
||||
|
||||
export type ChangeTodoStatusInput = {
|
||||
id: string;
|
||||
|
|
|
@ -4,12 +4,12 @@
|
|||
"private": true,
|
||||
"version": "1.0.1-0",
|
||||
"scripts": {
|
||||
"start": "concurrently 'yarn relay --watch' 'yarn serve --progress --color --mode=development'",
|
||||
"start": "concurrently 'yarn duct-tape-compiler --watch' 'yarn serve --progress --color --mode=development'",
|
||||
"build": "",
|
||||
"serve": "webpack serve --config webpack.config.ts",
|
||||
"extract-schema": "ts-node --project ./tsconfig-cli.json ../../packages/cli/bin/supermassive.js extract-schema ./src/schema/typeDefs.graphql",
|
||||
"generate:interfaces": "ts-node --project ./tsconfig-cli.json ../../packages/cli/bin/supermassive.js generate-interfaces ./src/schema/typeDefs.graphql",
|
||||
"relay": "relay-compiler --language graphitation --schema ./src/schema/typeDefs.graphql --src ./src"
|
||||
"duct-tape-compiler": "duct-tape-compiler --schema ./src/schema/typeDefs.graphql --src ./src --emitDocuments=false"
|
||||
},
|
||||
"dependencies": {
|
||||
"@apollo/client": "^3.7.15",
|
||||
|
@ -26,7 +26,6 @@
|
|||
"lodash": "^4.17.21",
|
||||
"react": "^17.0.2",
|
||||
"react-dom": "^17.0.2",
|
||||
"relay-compiler": "^12.0.0",
|
||||
"ts-loader": "^9.0.0",
|
||||
"ts-node": "^10.4.0",
|
||||
"typescript": "^4.6.2",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
;
|
||||
|
||||
import { FragmentRefs } from "@graphitation/apollo-react-relay-duct-tape";
|
||||
export type TodoFragment = {
|
||||
readonly id: string;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
;
|
||||
|
||||
import { FragmentRefs } from "@graphitation/apollo-react-relay-duct-tape";
|
||||
export type TodoListQueryVariables = {};
|
||||
export type TodoListQueryResponse = {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
;
|
||||
|
||||
import { FragmentRefs } from "@graphitation/apollo-react-relay-duct-tape";
|
||||
export type TodoUpdatesSubscriptionVariables = {
|
||||
limit: number;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
import * as yargs from "yargs";
|
||||
import { relayCompiler } from "relay-compiler";
|
||||
import { pluginFactory } from "./relayCompilerLanguagePlugin";
|
||||
|
||||
// TODO: This needs to be done here to ensure we get to mutate the transforms lists that get used.
|
||||
import { IRTransforms } from "relay-compiler";
|
||||
|
@ -25,9 +26,6 @@ function wrapTransform(
|
|||
transforms[transformIndex] = wrapperTransform(wrappedTransform);
|
||||
}
|
||||
|
||||
IRTransforms.printTransforms.push(annotateFragmentReferenceTransform); // TODO: Moving this up in the list might potentially optimize the query further
|
||||
IRTransforms.commonTransforms.unshift(enableNodeWatchQueryTransform);
|
||||
|
||||
wrapTransform(
|
||||
"filterDirectivesTransform",
|
||||
IRTransforms.printTransforms,
|
||||
|
@ -41,7 +39,7 @@ wrapTransform(
|
|||
|
||||
async function main() {
|
||||
const argv = await yargs
|
||||
.scriptName("nova-graphql-compiler")
|
||||
.scriptName("duct-tape-compiler")
|
||||
.options({
|
||||
src: {
|
||||
demandOption: false,
|
||||
|
@ -87,25 +85,38 @@ async function main() {
|
|||
default: false,
|
||||
type: "boolean",
|
||||
},
|
||||
printWatchQueries: {
|
||||
emitDocuments: {
|
||||
demandOption: false,
|
||||
default: true,
|
||||
type: "boolean",
|
||||
},
|
||||
emitNarrowObservables: {
|
||||
demandOption: false,
|
||||
default: true,
|
||||
type: "boolean",
|
||||
},
|
||||
emitQueryDebugComments: {
|
||||
demandOption: false,
|
||||
default: false,
|
||||
type: "boolean",
|
||||
},
|
||||
})
|
||||
.help().argv;
|
||||
// First ensure the schema env var is set...
|
||||
if (process.env.SCHEMA_PATH === undefined) {
|
||||
process.env.SCHEMA_PATH = argv.schema;
|
||||
|
||||
if (!argv.emitDocuments) {
|
||||
argv.emitNarrowObservables = false;
|
||||
argv.emitQueryDebugComments = false;
|
||||
}
|
||||
if (argv.printWatchQueries) {
|
||||
process.env.PRINT_WATCH_QUERIES = "true";
|
||||
|
||||
if (argv.emitNarrowObservables) {
|
||||
// TODO: Moving this up in the list might potentially optimize the query further
|
||||
IRTransforms.printTransforms.push(annotateFragmentReferenceTransform);
|
||||
IRTransforms.commonTransforms.unshift(enableNodeWatchQueryTransform);
|
||||
}
|
||||
// ...then load the language plugin, which looks for the schema path on module load (bad)
|
||||
const language = require("./relayCompilerLanguagePlugin");
|
||||
|
||||
return relayCompiler({
|
||||
...argv,
|
||||
language,
|
||||
language: pluginFactory(argv),
|
||||
extensions: ["ts", "tsx"], // FIXME: Why is this not taken from the language plugin?
|
||||
include: argv.include || ["**"],
|
||||
exclude: [
|
||||
|
|
|
@ -15,7 +15,7 @@ type PathWithConnectionDirective = [any[], Directive];
|
|||
* relay-compiler's filter directives transform
|
||||
*/
|
||||
export function retainConnectionDirectiveTransform(
|
||||
wrappedFilterDirectivesTransform: IRTransform
|
||||
wrappedFilterDirectivesTransform: IRTransform,
|
||||
): IRTransform {
|
||||
const filterDirectivesTransformWrapper: IRTransform = (context) => {
|
||||
let nextContext = context;
|
||||
|
@ -26,7 +26,8 @@ export function retainConnectionDirectiveTransform(
|
|||
|
||||
// Store @connection directives
|
||||
nextContext.forEachDocument((document) => {
|
||||
const fieldPathsWithConnectionDirectives: PathWithConnectionDirective[] = [];
|
||||
const fieldPathsWithConnectionDirectives: PathWithConnectionDirective[] =
|
||||
[];
|
||||
visit(document, {
|
||||
Directive(directiveNode, _key, _parent, path) {
|
||||
if (directiveNode.name === "connection") {
|
||||
|
@ -37,9 +38,8 @@ export function retainConnectionDirectiveTransform(
|
|||
}
|
||||
},
|
||||
});
|
||||
documentsWithConnectionDirectives[
|
||||
document.name
|
||||
] = fieldPathsWithConnectionDirectives;
|
||||
documentsWithConnectionDirectives[document.name] =
|
||||
fieldPathsWithConnectionDirectives;
|
||||
});
|
||||
|
||||
// Apply original upstream transform
|
||||
|
@ -54,7 +54,7 @@ export function retainConnectionDirectiveTransform(
|
|||
LinkedField(linkedFieldNode, _key, _parent, path) {
|
||||
const match = fieldPathsWithConnectionDirectives.find(
|
||||
([p, _]) =>
|
||||
path!.length === p.length && path!.every((x, i) => p[i] === x)
|
||||
path!.length === p.length && path!.every((x, i) => p[i] === x),
|
||||
);
|
||||
if (match) {
|
||||
const nextLinkedFieldNode: LinkedField = {
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
import invariant from "invariant";
|
||||
import { CompilerContext, Fragment } from "relay-compiler";
|
||||
|
||||
export function implementsNodeInterface(
|
||||
context: CompilerContext,
|
||||
fragmentDefinition: Fragment
|
||||
fragmentDefinition: Fragment,
|
||||
) {
|
||||
const schema = context.getSchema();
|
||||
const nodeType = schema.getTypeFromString("Node");
|
||||
schema.assertInterfaceType(nodeType);
|
||||
invariant(
|
||||
nodeType && schema.isInterface(nodeType),
|
||||
"Expected schema to define a Node interface in order to support narrow observables.",
|
||||
);
|
||||
return schema.getInterfaces(fragmentDefinition.type).includes(nodeType);
|
||||
}
|
||||
|
|
|
@ -4,17 +4,12 @@
|
|||
* Copyright 2018 Kaare Hoff Skovgaard kaare@kaareskovgaard.net, Eloy Durán eloy.de.enige@gmail.com
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This is currently in-flight and mostly re-uses code from the above mentioned package, where it's tested.
|
||||
*/
|
||||
/* istanbul ignore file */
|
||||
|
||||
import * as ts from "typescript";
|
||||
import {
|
||||
GraphQLTag,
|
||||
GraphQLTagFinder,
|
||||
} from "relay-compiler/lib/language/RelayLanguagePluginInterface";
|
||||
import { rewriteGraphitationDirectives } from "./rewriteGraphitationDirectives";
|
||||
// import { rewriteGraphitationDirectives } from "./rewriteGraphitationDirectives";
|
||||
|
||||
/**
|
||||
* @note Difference from the TS language plugin is that we only support hooks, so no need for HOCs.
|
||||
|
|
|
@ -1,71 +1,87 @@
|
|||
/**
|
||||
* NOTE: This is currently in-flight and mostly re-uses code from the above mentioned package, where it's tested.
|
||||
*/
|
||||
/* istanbul ignore file */
|
||||
|
||||
import { FormatModule } from "relay-compiler/lib/language/RelayLanguagePluginInterface";
|
||||
import { DocumentNode, parse, print } from "graphql";
|
||||
import { parse, print } from "graphql";
|
||||
import { optimizeDocumentNode } from "@graphql-tools/optimize";
|
||||
import { reduceNodeWatchQueryTransform } from "./formatModuleTransforms/reduceNodeWatchQueryTransform";
|
||||
import { schema } from "./schema";
|
||||
import invariant from "invariant";
|
||||
import { stripFragmentReferenceFieldSelectionTransform } from "./formatModuleTransforms/stripFragmentReferenceFieldSelectionTransform";
|
||||
import { extractMetadataTransform } from "./formatModuleTransforms/extractMetadataTransform";
|
||||
import { CompiledArtefactModule } from "./types";
|
||||
import { buildSchema, Source } from "graphql";
|
||||
import { readFileSync } from "fs";
|
||||
|
||||
import type { DocumentNode } from "graphql";
|
||||
import type { FormatModule } from "relay-compiler/lib/language/RelayLanguagePluginInterface";
|
||||
import type { CompiledArtefactModule } from "./types";
|
||||
|
||||
export interface FormatModuleOptions {
|
||||
emitDocuments: boolean;
|
||||
emitNarrowObservables: boolean;
|
||||
emitQueryDebugComments: boolean;
|
||||
schema: string;
|
||||
}
|
||||
|
||||
function printDocumentComment(document: DocumentNode) {
|
||||
return `/*\n${print(document).trim()}\n*/`;
|
||||
}
|
||||
|
||||
function generateExports(moduleName: string, docText: string) {
|
||||
const exports: CompiledArtefactModule = {};
|
||||
const originalDocument = parse(docText, { noLocation: true });
|
||||
const optimizedDocument = optimizeDocumentNode(originalDocument);
|
||||
export function formatModuleFactory(
|
||||
options: FormatModuleOptions,
|
||||
): FormatModule {
|
||||
const schema = options.emitNarrowObservables
|
||||
? buildSchema(
|
||||
new Source(readFileSync(options.schema, "utf-8"), options.schema),
|
||||
)
|
||||
: null;
|
||||
|
||||
if (!moduleName.endsWith("WatchNodeQuery.graphql")) {
|
||||
exports.executionQueryDocument =
|
||||
stripFragmentReferenceFieldSelectionTransform(optimizedDocument);
|
||||
function generateExports(moduleName: string, docText: string) {
|
||||
const exports: CompiledArtefactModule = {};
|
||||
const originalDocument = parse(docText, { noLocation: true });
|
||||
const optimizedDocument = optimizeDocumentNode(originalDocument);
|
||||
|
||||
if (!options.emitNarrowObservables) {
|
||||
exports.executionQueryDocument = optimizedDocument;
|
||||
} else {
|
||||
if (!moduleName.endsWith("WatchNodeQuery.graphql")) {
|
||||
exports.executionQueryDocument =
|
||||
stripFragmentReferenceFieldSelectionTransform(optimizedDocument);
|
||||
}
|
||||
|
||||
invariant(schema, "Expected a schema instance");
|
||||
exports.watchQueryDocument = reduceNodeWatchQueryTransform(
|
||||
schema,
|
||||
optimizedDocument,
|
||||
);
|
||||
|
||||
exports.metadata = extractMetadataTransform(exports.watchQueryDocument);
|
||||
}
|
||||
|
||||
return exports;
|
||||
}
|
||||
|
||||
invariant(schema, "Expected a schema to be passed in or set in the env");
|
||||
exports.watchQueryDocument = reduceNodeWatchQueryTransform(
|
||||
schema,
|
||||
optimizedDocument,
|
||||
);
|
||||
return ({ docText, hash, moduleName, typeText }) => {
|
||||
const exports = options.emitDocuments
|
||||
? docText && generateExports(moduleName, docText)
|
||||
: null;
|
||||
const components = [
|
||||
typeText,
|
||||
exports &&
|
||||
options.emitQueryDebugComments &&
|
||||
exports.executionQueryDocument &&
|
||||
printDocumentComment(exports.executionQueryDocument),
|
||||
exports &&
|
||||
options.emitQueryDebugComments &&
|
||||
exports.watchQueryDocument &&
|
||||
printDocumentComment(exports.watchQueryDocument),
|
||||
exports &&
|
||||
`export const documents: import("@graphitation/apollo-react-relay-duct-tape-compiler").CompiledArtefactModule = ${JSON.stringify(
|
||||
exports,
|
||||
null,
|
||||
2,
|
||||
)};`,
|
||||
].filter(Boolean) as string[];
|
||||
|
||||
exports.metadata = extractMetadataTransform(exports.watchQueryDocument);
|
||||
|
||||
return exports;
|
||||
}
|
||||
|
||||
export const formatModule: FormatModule = ({
|
||||
docText,
|
||||
hash,
|
||||
moduleName,
|
||||
typeText,
|
||||
}) => {
|
||||
const exports = docText && generateExports(moduleName, docText);
|
||||
const components = [
|
||||
typeText,
|
||||
exports &&
|
||||
exports.executionQueryDocument &&
|
||||
printDocumentComment(exports.executionQueryDocument),
|
||||
exports &&
|
||||
process.env.PRINT_WATCH_QUERIES &&
|
||||
exports.watchQueryDocument &&
|
||||
printDocumentComment(exports.watchQueryDocument),
|
||||
exports &&
|
||||
`export const documents: import("@graphitation/apollo-react-relay-duct-tape-compiler").CompiledArtefactModule = ${JSON.stringify(
|
||||
exports,
|
||||
null,
|
||||
2,
|
||||
)};`,
|
||||
].filter(Boolean) as string[];
|
||||
|
||||
return `/* tslint:disable */
|
||||
return `/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
${hash ? `/* ${hash} */\n` : ""};
|
||||
|
||||
${hash ? `/* ${hash} */\n` : ""}
|
||||
${components.join("\n\n")}`;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -31,19 +31,19 @@ const ALLOWED_REFETCH_QUERY_FIELD_SELECTIONS = [
|
|||
*/
|
||||
export function reduceNodeWatchQueryTransform(
|
||||
schema: GraphQLSchema,
|
||||
document: DocumentNode
|
||||
document: DocumentNode,
|
||||
): DocumentNode {
|
||||
const nodeType = schema.getType("Node");
|
||||
invariant(
|
||||
nodeType && isInterfaceType(nodeType),
|
||||
"Expected schema to define a Node interface"
|
||||
"Expected schema to define a Node interface in order to support narrow observables.",
|
||||
);
|
||||
|
||||
const typeInfo = new TypeInfo(schema);
|
||||
let retainFragment: string;
|
||||
|
||||
const removeNonWatchQueryFragmentNodes = (
|
||||
node: FragmentSpreadNode | FragmentDefinitionNode
|
||||
node: FragmentSpreadNode | FragmentDefinitionNode,
|
||||
) => {
|
||||
if (retainFragment && node.name.value === retainFragment) {
|
||||
return undefined;
|
||||
|
@ -69,13 +69,13 @@ export function reduceNodeWatchQueryTransform(
|
|||
OperationDefinition(operationDefinitionNode) {
|
||||
const selections = operationDefinitionNode.selectionSet!.selections;
|
||||
const fragmentSpreadNode = selections.find(
|
||||
(sel) => sel.kind === "FragmentSpread"
|
||||
(sel) => sel.kind === "FragmentSpread",
|
||||
) as FragmentSpreadNode;
|
||||
if (
|
||||
selections.length === 2 &&
|
||||
fragmentSpreadNode &&
|
||||
selections.find(
|
||||
(sel) => sel.kind === "Field" && sel.name.value === "__fragments"
|
||||
(sel) => sel.kind === "Field" && sel.name.value === "__fragments",
|
||||
)
|
||||
) {
|
||||
retainFragment = fragmentSpreadNode.name.value;
|
||||
|
@ -90,7 +90,7 @@ export function reduceNodeWatchQueryTransform(
|
|||
) {
|
||||
const selections = fieldNode.selectionSet!.selections;
|
||||
const fragmentSpreadSelections = selections.filter(
|
||||
(sel) => sel.kind === "FragmentSpread"
|
||||
(sel) => sel.kind === "FragmentSpread",
|
||||
) as FragmentSpreadNode[];
|
||||
// This is a refetch query only if...
|
||||
if (
|
||||
|
@ -100,7 +100,9 @@ export function reduceNodeWatchQueryTransform(
|
|||
selections.filter(
|
||||
(sel) =>
|
||||
sel.kind === "Field" &&
|
||||
!ALLOWED_REFETCH_QUERY_FIELD_SELECTIONS.includes(sel.name.value)
|
||||
!ALLOWED_REFETCH_QUERY_FIELD_SELECTIONS.includes(
|
||||
sel.name.value,
|
||||
),
|
||||
).length === 0 ||
|
||||
// ...and no inline fragment.
|
||||
selections.filter((sel) => sel.kind === "InlineFragment").length ===
|
||||
|
@ -113,6 +115,6 @@ export function reduceNodeWatchQueryTransform(
|
|||
},
|
||||
FragmentSpread: removeNonWatchQueryFragmentNodes,
|
||||
FragmentDefinition: removeNonWatchQueryFragmentNodes,
|
||||
})
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -2,28 +2,23 @@ import type { PluginInitializer } from "relay-compiler/lib/language/RelayLanguag
|
|||
import typescriptPluginInitializer from "relay-compiler-language-typescript";
|
||||
|
||||
import { find as findGraphQLTags } from "./findGraphQLTags";
|
||||
import { formatModule } from "./formatModule";
|
||||
import { formatModuleFactory } from "./formatModule";
|
||||
import { generateFactory } from "./typeGenerator";
|
||||
import type { FormatModuleOptions } from "./formatModule";
|
||||
|
||||
// TODO: Ideally this would be done from here, but this module is either loaded too late
|
||||
// or it's mutating the individual modules and the cli bin being used is the bundled
|
||||
// relay-compiler bin file.
|
||||
//
|
||||
// import { IRTransforms } from "relay-compiler";
|
||||
// import { enableNodeWatchQueryTransform } from "./enableNodeWatchQueryTransform";
|
||||
// IRTransforms.commonTransforms.unshift(enableNodeWatchQueryTransform);
|
||||
|
||||
const pluginInitializer: PluginInitializer = () => {
|
||||
const typescriptPlugin = typescriptPluginInitializer();
|
||||
return {
|
||||
...typescriptPlugin,
|
||||
findGraphQLTags,
|
||||
formatModule,
|
||||
typeGenerator: {
|
||||
...typescriptPlugin.typeGenerator,
|
||||
generate: generateFactory(typescriptPlugin.typeGenerator.generate),
|
||||
},
|
||||
export function pluginFactory(
|
||||
formatModuleOptions: FormatModuleOptions,
|
||||
): PluginInitializer {
|
||||
return () => {
|
||||
const typescriptPlugin = typescriptPluginInitializer();
|
||||
return {
|
||||
...typescriptPlugin,
|
||||
findGraphQLTags,
|
||||
formatModule: formatModuleFactory(formatModuleOptions),
|
||||
typeGenerator: {
|
||||
...typescriptPlugin.typeGenerator,
|
||||
generate: generateFactory(typescriptPlugin.typeGenerator.generate),
|
||||
},
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
export default pluginInitializer;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
/**
|
||||
* NOTE: This is currently in-flight and mostly re-uses code from the above mentioned package, where it's tested.
|
||||
*/
|
||||
|
||||
import {
|
||||
DirectiveNode,
|
||||
parse,
|
||||
|
@ -34,7 +30,7 @@ export function rewriteGraphitationDirectives(document: string) {
|
|||
_key,
|
||||
_parent,
|
||||
_path,
|
||||
ancestors
|
||||
ancestors,
|
||||
): DirectiveNode | undefined {
|
||||
switch (directiveNode.name.value) {
|
||||
case "watchNode": {
|
||||
|
@ -42,7 +38,7 @@ export function rewriteGraphitationDirectives(document: string) {
|
|||
invariant(
|
||||
!Array.isArray(fragmentDefinitionNode) &&
|
||||
fragmentDefinitionNode.kind === "FragmentDefinition",
|
||||
"Expected @watchNode to be used on a fragment"
|
||||
"Expected @watchNode to be used on a fragment",
|
||||
);
|
||||
return emitRefetchableDirective(fragmentDefinitionNode);
|
||||
}
|
||||
|
@ -65,7 +61,7 @@ export function rewriteGraphitationDirectives(document: string) {
|
|||
}
|
||||
|
||||
function emitRefetchableDirective(
|
||||
fragmentDefinitionNode: FragmentDefinitionNode
|
||||
fragmentDefinitionNode: FragmentDefinitionNode,
|
||||
): DirectiveNode {
|
||||
const fragmentName = fragmentDefinitionNode.name.value;
|
||||
const fragmentBaseName = fragmentName.replace(/Fragment$/, "");
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
import { buildSchema, Source } from "graphql";
|
||||
import { readFileSync } from "fs";
|
||||
// import invariant from "invariant";
|
||||
|
||||
// TODO: Just a dirty hack to side-step this issue for now.
|
||||
const schemaPath = process.env.SCHEMA_PATH;
|
||||
// invariant(schemaPath, "Expected the SCHEMA_PATH env variable to be set");
|
||||
|
||||
export const schema = schemaPath
|
||||
? buildSchema(new Source(readFileSync(schemaPath, "utf-8"), schemaPath))
|
||||
: undefined;
|
|
@ -1,8 +1,3 @@
|
|||
/**
|
||||
* NOTE: This is currently in-flight and mostly re-uses code from the above mentioned package, where it's tested.
|
||||
*/
|
||||
/* istanbul ignore file */
|
||||
|
||||
import { TypeGenerator } from "relay-compiler/lib/language/RelayLanguagePluginInterface";
|
||||
|
||||
export function generateFactory(wrappedGenerate: TypeGenerator["generate"]) {
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
"test": "monorepo-scripts test",
|
||||
"types": "monorepo-scripts types",
|
||||
"just": "monorepo-scripts",
|
||||
"duct-tape-compiler": "duct-tape-compiler --printWatchQueries --schema ./src/__tests__/schema.graphql --src ./src --exclude storeObservation/*FieldPolicy.test.ts"
|
||||
"duct-tape-compiler": "duct-tape-compiler --emitQueryDebugComments --schema ./src/__tests__/schema.graphql --src ./src --exclude storeObservation/*FieldPolicy.test.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@apollo/client": "^3.3.15",
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
;
|
||||
|
||||
import { FragmentRefs } from "@graphitation/apollo-react-relay-duct-tape";
|
||||
export type hooksTestFragment = {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
;
|
||||
|
||||
import { FragmentRefs } from "@graphitation/apollo-react-relay-duct-tape";
|
||||
export type hooksTestMutationVariables = {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
;
|
||||
|
||||
import { FragmentRefs } from "@graphitation/apollo-react-relay-duct-tape";
|
||||
export type hooksTestQueryVariables = {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
;
|
||||
|
||||
import { FragmentRefs } from "@graphitation/apollo-react-relay-duct-tape";
|
||||
export type hooksTestSubscriptionVariables = {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
;
|
||||
|
||||
/*
|
||||
query hooksTestWatchNodeQuery($id: ID!) {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
;
|
||||
|
||||
import { FragmentRefs } from "@graphitation/apollo-react-relay-duct-tape";
|
||||
export type compiledHooks_BackwardPaginationFragment = {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
;
|
||||
|
||||
import { FragmentRefs } from "@graphitation/apollo-react-relay-duct-tape";
|
||||
export type compiledHooks_BackwardPaginationFragment_PaginationQueryVariables = {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
;
|
||||
|
||||
import { FragmentRefs } from "@graphitation/apollo-react-relay-duct-tape";
|
||||
export type compiledHooks_ChildFragment = {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
;
|
||||
|
||||
/*
|
||||
query compiledHooks_ChildWatchNodeQuery($id: ID!) {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
;
|
||||
|
||||
import { FragmentRefs } from "@graphitation/apollo-react-relay-duct-tape";
|
||||
export type compiledHooks_ForwardPaginationFragment = {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
;
|
||||
|
||||
import { FragmentRefs } from "@graphitation/apollo-react-relay-duct-tape";
|
||||
export type compiledHooks_ForwardPaginationFragment_PaginationQueryVariables = {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
;
|
||||
|
||||
import { FragmentRefs } from "@graphitation/apollo-react-relay-duct-tape";
|
||||
export type compiledHooks_QueryTypeFragment = {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
;
|
||||
|
||||
/*
|
||||
query compiledHooks_QueryTypeWatchNodeQuery {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
;
|
||||
|
||||
import { FragmentRefs } from "@graphitation/apollo-react-relay-duct-tape";
|
||||
export type compiledHooks_RefetchableFragment = {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
;
|
||||
|
||||
import { FragmentRefs } from "@graphitation/apollo-react-relay-duct-tape";
|
||||
export type compiledHooks_RefetchableFragment_RefetchQueryVariables = {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
;
|
||||
|
||||
import { FragmentRefs } from "@graphitation/apollo-react-relay-duct-tape";
|
||||
export type compiledHooks_Root_executionQueryVariables = {
|
||||
|
|
38
yarn.lock
38
yarn.lock
|
@ -167,7 +167,7 @@
|
|||
"@jridgewell/trace-mapping" "^0.3.17"
|
||||
jsesc "^2.5.1"
|
||||
|
||||
"@babel/generator@^7.22.3":
|
||||
"@babel/generator@^7.21.5":
|
||||
version "7.22.3"
|
||||
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.22.3.tgz#0ff675d2edb93d7596c5f6728b52615cfc0df01e"
|
||||
integrity sha512-C17MW4wlk//ES/CJDL51kPNwl+qiBQyN7b9SKyVp11BLGFeSPoVaHrv+MNt8jwQFhQWowW88z1eeBx3pFz9v8A==
|
||||
|
@ -210,7 +210,7 @@
|
|||
resolved "https://registry.yarnpkg.com/@babel/helper-environment-visitor/-/helper-environment-visitor-7.21.5.tgz#c769afefd41d171836f7cb63e295bedf689d48ba"
|
||||
integrity sha512-IYl4gZ3ETsWocUWgsFZLM5i1BYx9SoemminVEXadgLBa9TdeorzgLKm8wWLA6J1N/kT3Kch8XIk1laNzYoHKvQ==
|
||||
|
||||
"@babel/helper-environment-visitor@^7.22.1":
|
||||
"@babel/helper-environment-visitor@^7.21.5":
|
||||
version "7.22.1"
|
||||
resolved "https://registry.yarnpkg.com/@babel/helper-environment-visitor/-/helper-environment-visitor-7.22.1.tgz#ac3a56dbada59ed969d712cf527bd8271fe3eba8"
|
||||
integrity sha512-Z2tgopurB/kTbidvzeBrc2To3PUP/9i5MUe+fU6QJCQDyPwSH2oRapkLw3KGECDYSjhQZCNxEvNvZlLw8JjGwA==
|
||||
|
@ -356,7 +356,7 @@
|
|||
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.21.5.tgz#821bb520118fd25b982eaf8d37421cf5c64a312b"
|
||||
integrity sha512-J+IxH2IsxV4HbnTrSWgMAQj0UEo61hDA4Ny8h8PCX0MLXiibqHbqIOVneqdocemSBc22VpBKxt4J6FQzy9HarQ==
|
||||
|
||||
"@babel/parser@^7.22.4":
|
||||
"@babel/parser@^7.21.5":
|
||||
version "7.22.4"
|
||||
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.22.4.tgz#a770e98fd785c231af9d93f6459d36770993fb32"
|
||||
integrity sha512-VLLsx06XkEYqBtE5YGPwfSGwfrjnyPP5oiGty3S8pQLFDFLaS8VwWSIxkTXpcvr5zeYLE6+MBNl2npl/YnfofA==
|
||||
|
@ -705,7 +705,7 @@
|
|||
"@babel/helper-validator-identifier" "^7.19.1"
|
||||
to-fast-properties "^2.0.0"
|
||||
|
||||
"@babel/types@^7.21.4", "@babel/types@^7.22.3", "@babel/types@^7.22.4":
|
||||
"@babel/types@^7.21.4", "@babel/types@^7.21.5", "@babel/types@^7.22.3":
|
||||
version "7.22.4"
|
||||
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.22.4.tgz#56a2653ae7e7591365dabf20b76295410684c071"
|
||||
integrity sha512-Tx9x3UBHTTsMSW85WB2kphxYQVvrZ/t1FxD88IpSgIjiUJlCm9z+xWIDwyo1vffTwSqteqyznB8ZE9vYYk16zA==
|
||||
|
@ -10614,28 +10614,6 @@ relay-compiler@11.0.2:
|
|||
signedsource "^1.0.0"
|
||||
yargs "^15.3.1"
|
||||
|
||||
relay-compiler@^10:
|
||||
version "10.1.3"
|
||||
resolved "https://registry.yarnpkg.com/relay-compiler/-/relay-compiler-10.1.3.tgz#76ec4fd5d16f5b6aae61183f64b5caaef27f2525"
|
||||
integrity sha512-AJoET3U8PrLXiA1/jmcr5beR/928+8c8qf46nOuumaNXhTfJC2RvN2fpD0APF0Fti+oKBxwKcQJ93R5BK6A2xw==
|
||||
dependencies:
|
||||
"@babel/core" "^7.0.0"
|
||||
"@babel/generator" "^7.5.0"
|
||||
"@babel/parser" "^7.0.0"
|
||||
"@babel/runtime" "^7.0.0"
|
||||
"@babel/traverse" "^7.0.0"
|
||||
"@babel/types" "^7.0.0"
|
||||
babel-preset-fbjs "^3.3.0"
|
||||
chalk "^4.0.0"
|
||||
fb-watchman "^2.0.0"
|
||||
fbjs "^3.0.0"
|
||||
glob "^7.1.1"
|
||||
immutable "~3.7.6"
|
||||
nullthrows "^1.1.1"
|
||||
relay-runtime "10.1.3"
|
||||
signedsource "^1.0.0"
|
||||
yargs "^15.3.1"
|
||||
|
||||
relay-compiler@^12.0.0:
|
||||
version "12.0.0"
|
||||
resolved "https://registry.yarnpkg.com/relay-compiler/-/relay-compiler-12.0.0.tgz#9f292d483fb871976018704138423a96c8a45439"
|
||||
|
@ -10659,14 +10637,6 @@ relay-compiler@^12.0.0:
|
|||
signedsource "^1.0.0"
|
||||
yargs "^15.3.1"
|
||||
|
||||
relay-runtime@10.1.3:
|
||||
version "10.1.3"
|
||||
resolved "https://registry.yarnpkg.com/relay-runtime/-/relay-runtime-10.1.3.tgz#1d7bfe590b50cd7f18f6d1c0f20df71fe5bb451a"
|
||||
integrity sha512-NSh4CaRRpUaziK72h4T5uKw6rvHovmS/xD9+czqUYg6yKv22ajwBE6SWmjwTSKnt2NBzIfDjh2C3heo9pLbvtg==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.0.0"
|
||||
fbjs "^3.0.0"
|
||||
|
||||
relay-runtime@11.0.2:
|
||||
version "11.0.2"
|
||||
resolved "https://registry.yarnpkg.com/relay-runtime/-/relay-runtime-11.0.2.tgz#c3650477d45665b9628b852b35f203e361ad55e8"
|
||||
|
|
Загрузка…
Ссылка в новой задаче