Skip to content

Commit

Permalink
Add cli events and thread GraphQL
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrove committed Aug 4, 2022
1 parent fdd0c82 commit 214efbf
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 34 deletions.
17 changes: 9 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"author": "sgrove",
"license": "MIT",
"dependencies": {
"graphql": "16.0.0",
"graphql": "16.5.0",
"node-fetch": "^2.6.0",
"uuid": "^8.3.2"
},
Expand Down
100 changes: 100 additions & 0 deletions src/cliEventHelpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
export const OneGraphNetlifyCliSessionTestEventSdl = `type OneGraphNetlifyCliSessionTestEvent {
id: String!
sessionId: String!
createdAt: String!
payload: JSON!
}`;

export type OneGraphNetlifyCliSessionTestEvent = {
__typename: "OneGraphNetlifyCliSessionTestEvent";
id: string;
sessionId: string;
createdAt: string;
payload: Record<string, unknown>;
};

export const OneGraphNetlifyCliSessionGenerateHandlerEventSdl = `type OneGraphNetlifyCliSessionGenerateHandlerEvent {
id: String!
sessionId: String!
createdAt: String!
payload: {
cliSessionId: String!
operationId: String
codeGeneratorId: String!
options: JSON
}
}`;

export type OneGraphNetlifyCliSessionGenerateHandlerEvent = {
__typename: "OneGraphNetlifyCliSessionGenerateHandlerEvent";
id: string;
sessionId: string;
createdAt: string;
payload: {
cliSessionId: string;
operationId: string;
codeGeneratorId: string;
options?: Record<string, unknown> | null;
};
};

export const OneGraphNetlifyCliSessionOpenFileEventSdl = `type OneGraphNetlifyCliSessionOpenFileEvent {
id: String!
sessionId: String!
createdAt: String!
payload: {
filePath: String!
}
}`;

export type OneGraphNetlifyCliSessionOpenFileEvent = {
__typename: "OneGraphNetlifyCliSessionOpenFileEvent";
id: string;
sessionId: string;
createdAt: string;
payload: {
filePath: string;
};
};

export const OneGraphNetlifyCliSessionPersistedLibraryUpdatedEventSdl = `type OneGraphNetlifyCliSessionPersistedLibraryUpdatedEvent {
id: String!
sessionId: String!
createdAt: String!
payload: {
docId: String!
}
}`;

export type OneGraphNetlifyCliSessionPersistedLibraryUpdatedEvent = {
__typename: "OneGraphNetlifyCliSessionOpenFileEvent";
id: string;
sessionId: string;
createdAt: string;
payload: {
docId: string;
};
};

export const OneGraphNetlifyCliSessionFileWrittenEventSdl = `type OneGraphNetlifyCliSessionFileWrittenEvent {
id: String!
sessionId: String!
createdAt: String!
payload: {
editor: String
filePath: String!
}
audience: String!
}`;

export type OneGraphNetlifyCliSessionFileWrittenEvent = {
__typename: "OneGraphNetlifyCliSessionFileWrittenEvent";
id: string;
sessionId: string;
createdAt: string;
payload: {
editor: string | null;
filePath: string;
};
audience: "UI" | "CLI";
};
27 changes: 26 additions & 1 deletion src/codegen/codegenHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,41 @@ type CodeGeneratorSupportableDefinitionType =
| "subscription"
| "fragment";

export type GenerateHandlerFunctionOptions = {
schemaSdl: string;
inputTypename: string;
defaultValue?: Record<string, unknown>;
};

export type GenerateHandlerFunctionOptionsDeserialized = {
schema: GraphQL.GraphQLSchema;
inputTypename: string;
defaultValue?: Record<string, unknown>;
};

export type CodeGenerator = {
generatePreview?: GenerateHandlerPreviewFunction;
generateHandler: GenerateHandlerFunction;
generateHandlerOptions?: { schemaSdl: string; inputTypename: string };
generateHandlerOptions?: GenerateHandlerFunctionOptions;
supportedDefinitionTypes: CodeGeneratorSupportableDefinitionType[];
name: string;
id: string;
version: string;
};

export type CodeGeneratorMeta = {
id: string;
name: string;
options: GenerateHandlerFunctionOptions | null;
supportedDefinitionTypes: CodeGeneratorSupportableDefinitionType[];
};

export type CodegenModuleMeta = {
id: string;
version: string;
generators: CodeGeneratorMeta[];
};

export type CodegenModule = {
id: string;
version: string;
Expand Down
2 changes: 2 additions & 0 deletions src/generatedOneGraphClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ const fetchNetlifyGraph = function fetchNetlifyGraph(input) {
response.then((result) => {
// Check response headers for a 304 Not Modified
if (result.status === 304) {
// Drain the body so the connection will be closed
result.text();
// Return the cached result
resolve(cachedResultValue);
} else if (result.status === 200) {
Expand Down
52 changes: 29 additions & 23 deletions src/graphqlHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ export function listCount(GraphQL: typeof GraphQLPackage, gqlType) {
totalCount = totalCount + 1;

if (totalCount > 30) {
console.warn("Bailing on potential infinite recursion");
internalConsole.warn("Bailing on potential infinite recursion");
return -99;
}

Expand Down Expand Up @@ -549,7 +549,7 @@ export function typeScriptDefinitionObjectForOperation(
parentNamedType.getFields()[name];

if (!field) {
console.warn(
internalConsole.warn(
"Could not find field",
name,
"in",
Expand Down Expand Up @@ -621,7 +621,10 @@ export function typeScriptDefinitionObjectForOperation(
}
}
} else {
console.warn("objectHelper got a non-field selection", selection);
internalConsole.warn(
"objectHelper got a non-field selection",
selection
);
}
});

Expand Down Expand Up @@ -696,7 +699,7 @@ export function typeScriptDefinitionObjectForOperation(

return outEnum;
} else {
console.warn("Unrecognized type in operation", parentGqlType);
internalConsole.warn("Unrecognized type in operation", parentGqlType);
}
};

Expand Down Expand Up @@ -934,19 +937,6 @@ export function typeScriptDefinitionObjectForFragment(
(isObjectType(parentNamedType) || isInterfaceType(parentNamedType)) &&
parentNamedType.getFields()[name];

if (!field) {
console.warn(
"Could not find field",
name,
"on",
parentNamedType.name,
"among",
// @ts-ignore
Object.keys(parentNamedType.getFields())
);
return;
}

if (name.startsWith("__")) {
return {
kind: "object",
Expand All @@ -962,6 +952,19 @@ export function typeScriptDefinitionObjectForFragment(
};
}

if (!field) {
internalConsole.warn(
"Could not find field",
name,
"on",
parentNamedType.name,
"among",
// @ts-ignore
Object.keys(parentNamedType.getFields())
);
return;
}

let gqlType = field.type;
let namedType = getNamedType(gqlType);
const isNullable = isNullableType(gqlType);
Expand Down Expand Up @@ -1024,7 +1027,10 @@ export function typeScriptDefinitionObjectForFragment(
}
}
} else {
console.warn("objectHelper got a non-field selection", selection);
internalConsole.warn(
"objectHelper got a non-field selection",
selection
);
}
});

Expand Down Expand Up @@ -1099,7 +1105,7 @@ export function typeScriptDefinitionObjectForFragment(

return outEnum;
} else {
console.warn("Unrecognized type in fragment", parentGqlType);
internalConsole.warn("Unrecognized type in fragment", parentGqlType);
}
};

Expand Down Expand Up @@ -1492,7 +1498,7 @@ export const formInput = (

const hydratedType = typeFromAST(schema, def.type);
if (!hydratedType) {
console.warn("\tCould not hydrate type for ", def.type);
internalConsole.warn("\tCould not hydrate type for ", def.type);
return null;
}
// const required = isNonNullType(hydratedType);
Expand Down Expand Up @@ -1623,7 +1629,7 @@ export const remixFormInput = (

const hydratedType = typeFromAST(schema, def.type);
if (!hydratedType) {
console.warn("\tCould not hydrate type for ", def.type);
internalConsole.warn("\tCould not hydrate type for ", def.type);
return null;
}
// const required = isNonNullType(hydratedType);
Expand Down Expand Up @@ -1790,7 +1796,7 @@ export const gatherHardcodedValues = (

return hardCodedValues;
} catch (e) {
console.warn("Error parsing query", e);
internalConsole.warn("Error parsing query", e);
return [];
}
};
Expand Down Expand Up @@ -1824,7 +1830,7 @@ export const extractPersistableOperation = (
FragmentSpread: { enter: fragmentExtractor },
});
} else {
console.warn(
internalConsole.warn(
"Could not find fragment definition for referenced fragment: ",
fragmentName
);
Expand Down
2 changes: 1 addition & 1 deletion src/netlifyGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2016,7 +2016,7 @@ export const generatePersistedFunctionsSource = async (
...result,
attemptedFunction: fn,
});
console.warn(
internalConsole.warn(
"Failed to persist function",
fn.operationName,
result.errors
Expand Down

0 comments on commit 214efbf

Please sign in to comment.