Skip to content

Commit 86363d0

Browse files
committed
Changed code to upload schema onto lambda, made resolver template take in schema file as separate file instead of input, made template static by not accepting any input except the timestamp
1 parent 98f9006 commit 86363d0

File tree

5 files changed

+24
-8
lines changed

5 files changed

+24
-8
lines changed

doc/todoExample.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Let's now run this schema through the utility and create the GraphQL API in AWS
2121

2222
`neptune-for-graphql --input-schema-file ./samples/todo.schema.graphql --create-update-aws-pipeline --create-update-aws-pipeline-name TodoExample --create-update-aws-pipeline-neptune-endpoint` <*your-neptune-database-endpoint:port*> ` --output-resolver-query-https`
2323

24-
Te utility created a new file in the *output* folder called *TodoExample.source.graphql*, and the GraphQL API in AppSync. As you can see below, the utility inferenced:
24+
The utility created a new file in the *output* folder called *TodoExample.source.graphql*, and the GraphQL API in AppSync. As you can see below, the utility inferenced:
2525

2626
- In the type *Todo* it added *@relationship* for a new type *CommentEdge*. This is instructing the resolver to connect *Todo* to *Comment* using a graph database edge called *CommentEdge*.
2727
- A new input called *TodoInput* was added to help the queries and the mutations.

src/main.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -519,11 +519,21 @@ async function main() {
519519
// Validate schema
520520
schemaModel = validatedSchemaModel(schemaModel, quiet);
521521

522+
// Generate schema for resolver
523+
const queryDataModelJSON = JSON.stringify(schemaModel, null, 2);
524+
let resolverSchemaFile = `${outputFolderPath}/resolver.schema.graphql`
525+
try {
526+
writeFileSync(resolverSchemaFile, queryDataModelJSON);
527+
loggerInfo('Wrote schema for resolver to file: ' + yellow(resolverSchemaFile), {toConsole: true});
528+
} catch (err) {
529+
loggerError('Error writing schema for resolver to file: ' + yellow(resolverSchemaFile), err);
530+
}
531+
522532
// Generate AWS Lambda resolver for AppSync and Amazon Neptune
523-
outputLambdaResolver = resolverJS(schemaModel, queryLanguage, queryClient, __dirname);
533+
outputLambdaResolver = resolverJS(queryLanguage, queryClient, __dirname);
524534

525535
// Generate generic Javascript resolver
526-
outputJSResolver = resolverJS(schemaModel, queryLanguage, queryClient, __dirname);
536+
outputJSResolver = resolverJS(queryLanguage, queryClient, __dirname);
527537
}
528538

529539
// ****************************************************************************

src/resolverJS.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@ permissions and limitations under the License.
1313
import { readFileSync} from 'fs';
1414
import { loggerError } from "./logger.js";
1515

16-
function resolverJS (schemaModel, queryLanguage, queryClient, __dirname) {
16+
function resolverJS (queryLanguage, queryClient, __dirname) {
1717
let code = '';
18-
const queryDataModelJSON = JSON.stringify(schemaModel, null, 2);
1918

2019
if (queryLanguage == 'opencypher') {
2120
try {
2221
code = readFileSync(__dirname + '/../templates/JSResolverOCHTTPSTemplate.js');
2322
code = code.toString().replace('TIMESTAMP HERE', (new Date()).toISOString());
24-
code = code.toString().replace('INSERT SCHEMA DATA MODEL HERE', queryDataModelJSON);
2523
} catch (err) {
2624
loggerError('No resolver template found.', err);
2725
}

src/zipPackage.js

+7
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ export async function createLambdaDeploymentPackage({outputZipFilePath, template
5050
source: path.join(getModulePath(), '/../templates/queryHttpNeptune.mjs')
5151
})
5252
}
53+
54+
filePaths.push({
55+
source: path.join(getModulePath(), '/../output/resolver.schema.graphql')
56+
})
57+
5358
await createZip({
5459
targetZipFilePath: outputZipFilePath,
5560
includePaths: filePaths
@@ -81,7 +86,9 @@ export async function createApolloDeploymentPackage({zipFilePath, resolverFilePa
8186
includePaths: [
8287
{source: path.join(modulePath, '/../templates/ApolloServer')},
8388
{source: resolverFilePath, target: 'output.resolver.graphql.js'},
89+
{source: resolverFilePath, target: 'resolver.schema.graphql'},
8490
{source: schemaFilePath, target: 'output.schema.graphql'},
91+
8592
// querying neptune using SDK not yet supported
8693
{source: path.join(modulePath, '/../templates/queryHttpNeptune.mjs')}
8794
],

templates/JSResolverOCHTTPSTemplate.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ permissions and limitations under the License.
1212

1313
import { astFromValue, buildASTSchema, typeFromAST, GraphQLID, GraphQLInputObjectType } from 'graphql';
1414
import { gql } from 'graphql-tag'; // GraphQL library to parse the GraphQL query
15+
import {readFileSync} from "fs";
1516

1617
const useCallSubquery = false;
1718

1819
// TIMESTAMP HERE
1920

20-
const schemaDataModelJSON = `INSERT SCHEMA DATA MODEL HERE`;
21-
21+
let schemaDataModelJSON = readFileSync('resolver.schema.graphql', 'utf-8');
22+
2223
const schemaDataModel = JSON.parse(schemaDataModelJSON);
2324

2425
const schema = buildASTSchema(schemaDataModel, { assumeValidSDL: true });

0 commit comments

Comments
 (0)