How to use the graphql-migrations.migrate function in graphql-migrations

To help you get started, we’ve selected a few graphql-migrations 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 aerogear / graphql-testx / src / InMemoryDatabase.ts View on Github external
export async function initInMemoryDatabase(
  schema: string
): Promise {
  // initialize the knex db
  const knex = Knex({
    client: "sqlite3",
    connection: { filename: ":memory:" }
  });

  // migrate the schema
  const strategy = new DropCreateDatabaseAlways("sqlite3", knex);
  await migrate(schema, strategy);

  return new InMemoryDatabase(knex);
}
github Urigo / graphql-cli / packages / commands / generate / src / index.ts View on Github external
export async function createDatabaseMigration(schema: string, config: GenerateConfig) {
  const db = knex({
    client: config.db.database,
    connection: config.db.dbConfig,
  });
  // FIXME move to UpdateDatabaseIfChanges after adding relationships support
  const dbInitialization = new DropCreateDatabaseAlways(config.db.database, db);

  await migrate(schema, dbInitialization);
  return new Promise(resolve => db.destroy(resolve));
}
github aerogear / graphback / packages / graphback-cli / src / helpers / db.ts View on Github external
logError(`No graphql file found inside ${process.cwd()}/model folder.`)
      process.exit(0)
    }

    if (database === 'sqlite3') {
      await execa('touch', ['db.sqlite'])
    }

    const dbConfig = {
      client: config.db.database,
      connection: config.db.dbConfig
    }

    const schemaText = loadSchema(folders.model);

    databaseOperations = await migrate(dbConfig, schemaText, {
      dbSchemaName: config.db.schema
    });

  } catch (err) {
    handleError(err)
  }

  return databaseOperations;
}
github aerogear / graphback / examples / runtime-example / src / runtime.ts View on Github external
export const createRuntime = async (client: Knex) => {
  const schemaText = loadSchema(jsonConfig.folders.model);

  const backend = new GraphQLBackendCreator(schemaText, jsonConfig.graphqlCRUD);
  const dbClientProvider = new PgKnexDBDataProvider(client);

  const dbConfig = {
    client: jsonConfig.db.database,
    connection: jsonConfig.db.dbConfig
  };

  migrate(dbConfig, schemaText, {
    dbSchemaName: jsonConfig.db.schema
  }).then((ops) => {
    console.log(ops);
  });

  const pubSub = new PubSub();
  const runtime = await backend.createRuntime(dbClientProvider, pubSub);
  const generatedSchema = runtime.schema;

  const executableSchema = makeExecutableSchema({
    typeDefs: gql`${generatedSchema}`,
    resolvers: runtime.resolvers,
    resolverValidationOptions: {
      requireResolversForResolveType: false
    }
  });

graphql-migrations

Create & migrate Databases from GraphQL Schema

Apache-2.0
Latest version published 4 years ago

Package Health Score

45 / 100
Full package analysis

Similar packages