How to use graphql-relational-schema-transformer - 4 common examples

To help you get started, we’ve selected a few graphql-relational-schema-transformer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws-amplify / amplify-cli / packages / amplify-category-api / provider-utils / awscloudformation / service-walkthroughs / appSync-rds-walkthrough.js View on Github external
async function selectDatabase(context, inputs, clusterArn, secretArn, AWS) {
  // Database Name Question
  const DataApi = new AWS.RDSDataService();
  const params = new DataApiParams();
  params.secretArn = secretArn;
  params.resourceArn = clusterArn;
  params.sql = 'SHOW databases';

  spinner.start('Fetching Aurora Serverless cluster...');
  const dataApiResult = await DataApi.executeStatement(params).promise();

  // eslint-disable-next-line prefer-destructuring
  const records = dataApiResult.records;
  const databaseList = [];

  for (let i = 0; i < records.length; i += 1) {
    const recordValue = records[i][0].stringValue;
    // ignore the three meta tables that the cluster creates
    if (!['information_schema', 'performance_schema', 'mysql'].includes(recordValue)) {
      databaseList.push(recordValue);
github aws-amplify / amplify-cli / packages / amplify-category-api / commands / api / add-graphql-datasource.js View on Github external
teamProviderInfo[currEnv][categories][category][resourceName][rdsDatabaseName] = answers.databaseName;

        fs.writeFileSync(teamProviderInfoFilePath, JSON.stringify(teamProviderInfo, null, 4));

        const backendConfigFilePath = amplify.pathManager.getBackendConfigFilePath();
        const backendConfig = context.amplify.readJsonFile(backendConfigFilePath);

        backendConfig[category][resourceName][rdsInit] = true;

        fs.writeFileSync(backendConfigFilePath, JSON.stringify(backendConfig, null, 4));

        /**
         * Load the MySqlRelationalDBReader
         */
        // eslint-disable-next-line max-len
        const dbReader = new AuroraServerlessMySQLDatabaseReader(
          answers.region,
          answers.secretStoreArn,
          answers.dbClusterArn,
          answers.databaseName,
          AWS
        );

        /**
         * Instantiate a new Relational Schema Transformer and perform
         * the db instrospection to get the GraphQL Schema and Template Context
         */
        const relationalSchemaTransformer = new RelationalDBSchemaTransformer(dbReader, answers.databaseName);
        return relationalSchemaTransformer.introspectDatabaseSchema();
      })
      .then(graphqlSchemaContext => {
github aws-amplify / amplify-cli / packages / amplify-category-api / commands / api / add-graphql-datasource.js View on Github external
* Load the MySqlRelationalDBReader
         */
        // eslint-disable-next-line max-len
        const dbReader = new AuroraServerlessMySQLDatabaseReader(
          answers.region,
          answers.secretStoreArn,
          answers.dbClusterArn,
          answers.databaseName,
          AWS
        );

        /**
         * Instantiate a new Relational Schema Transformer and perform
         * the db instrospection to get the GraphQL Schema and Template Context
         */
        const relationalSchemaTransformer = new RelationalDBSchemaTransformer(dbReader, answers.databaseName);
        return relationalSchemaTransformer.introspectDatabaseSchema();
      })
      .then(graphqlSchemaContext => {
github aws-amplify / amplify-cli / packages / amplify-category-api / commands / api / add-graphql-datasource.js View on Github external
fs.ensureFileSync(graphqlSchemaFilePath);
        const graphqlSchemaRaw = fs.readFileSync(graphqlSchemaFilePath, 'utf8');
        const currGraphQLSchemaDoc = graphql.parse(graphqlSchemaRaw);

        const rdsGraphQLSchemaDoc = graphqlSchemaContext.schemaDoc;

        const concatGraphQLSchemaDoc = mergeTypes([currGraphQLSchemaDoc, rdsGraphQLSchemaDoc], { all: true });

        fs.writeFileSync(graphqlSchemaFilePath, concatGraphQLSchemaDoc, 'utf8');
        const resolversDir = `${projectBackendDirPath}/${category}/${resourceName}/resolvers`;

        /**
         * Instantiate a new Relational Template Generator and create
         * the template and relational resolvers
         */
        const templateGenerator = new RelationalDBTemplateGenerator(graphqlSchemaContext);
        context[rdsResourceName] = resourceName;
        context[rdsDatasource] = datasource;
        let template = templateGenerator.createTemplate(context);
        template = templateGenerator.addRelationalResolvers(template, resolversDir);
        const cfn = templateGenerator.printCloudformationTemplate(template);

        /**
         * Add the generated the CFN to the appropriate nested stacks directory
         */
        const stacksDir = `${projectBackendDirPath}/${category}/${resourceName}/stacks`;
        const writeToPath = `${stacksDir}/${resourceName}-${databaseName}-rds.json`;
        fs.writeFileSync(writeToPath, cfn, 'utf8');

        return datasource;
      })
      .then(datasourceName => {

graphql-relational-schema-transformer

An AppSync model transform that takes a relational database and turns that into a GraphQL API.

Apache-2.0
Latest version published 5 months ago

Package Health Score

89 / 100
Full package analysis