How to use graphql-import - 10 common examples

To help you get started, we’ve selected a few graphql-import 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 graphql-cli / graphql-cli-prepare / src / prepare.ts View on Github external
private processBindings(
    schemaPath: string | undefined
  ): { 'prepare-binding': { output: string; generator: string } } {
    const generator: string = this.determineGenerator()
    // TODO: This does not support custom generators
    const extension = generator.endsWith('ts') ? 'ts' : 'js'
    const outputPath: string = this.determineBindingOutputPath(extension)
    const schema: string = this.determineInputSchema(schemaPath)

    const schemaContents: string = importSchema(schema)
    const finalSchema: string = generateCode(schemaContents, generator)
    fs.writeFileSync(outputPath, finalSchema, { flag: 'w' })

    return { 'prepare-binding': { output: outputPath, generator: generator } }
  }
github nashdev / jobs / src / server / middleware / graphql.js View on Github external
function buildTypeDefsString(typeDefs) {
  let typeDefinitions = mergeTypeDefs(typeDefs);

  // read from .graphql file if path provided
  if (typeDefinitions.endsWith('graphql')) {
    const schemaPath = path.resolve(typeDefinitions);

    if (!fs.existsSync(schemaPath)) {
      throw new Error(`No schema found for path: ${schemaPath}`);
    }

    typeDefinitions = importSchema(schemaPath);
  }

  return typeDefinitions;
}
github prisma-labs / graphql-yoga / src / lambda.ts View on Github external
resolverValidationOptions,
        typeDefs,
        resolvers,
      } = props

      // read from .graphql file if path provided
      if (typeDefs.endsWith('graphql')) {
        const schemaPath = path.isAbsolute(typeDefs)
          ? path.resolve(typeDefs)
          : path.resolve(typeDefs)

        if (!fs.existsSync(schemaPath)) {
          throw new Error(`No schema found for path: ${schemaPath}`)
        }

        typeDefs = importSchema(schemaPath)
      }

      this.executableSchema = makeExecutableSchema({
        directiveResolvers,
        schemaDirectives,
        resolverValidationOptions,
        typeDefs,
        resolvers,
      })
    }

    if (props.middlewares) {
      const { schema, fragmentReplacements } = applyFieldMiddleware(
        this.executableSchema,
        ...props.middlewares,
      )
github maticzav / graphql-server-github-auth-example / src / index.ts View on Github external
import { importSchema } from 'graphql-import'
import { GraphQLServer } from 'graphql-yoga'
import { Prisma } from './generated/prisma'

import { resolvers } from './resolvers'

// Config --------------------------------------------------------------------

const APP_SCHEMA_PATH = './src/schema.graphql'

const typeDefs = importSchema(APP_SCHEMA_PATH)

// Server --------------------------------------------------------------------

const server = new GraphQLServer({
  typeDefs,
  resolvers,
  context: req => ({
    ...req,
    db: new Prisma({
      endpoint: process.env.PRISMA_ENDPOINT,
      secret: process.env.PRISMA_SECRET
    })
  })
})

server.start({ port: 5000 },() => {
github maticzav / graphql-server-file-upload-example / src / index.ts View on Github external
import { GraphQLServer } from "graphql-yoga"
import { importSchema } from "graphql-import"
import { S3 } from 'aws-sdk'
import { Prisma } from "./generated/prisma"
import { resolvers } from "./resolvers"
import { files } from './files'

// Config --------------------------------------------------------------------

const APP_SCHEMA_PATH = './src/schema.graphql'

const typeDefs = importSchema(APP_SCHEMA_PATH)

const s3client = new S3({
  accessKeyId: process.env.S3_KEY,
  secretAccessKey: process.env.S3_SECRET,
  params: {
    Bucket: process.env.S3_BUCKET
  }
})


// Server --------------------------------------------------------------------

const server = new GraphQLServer({
  typeDefs,
  resolvers,
  context: req => ({
github davidnguyen179 / typescript-graphql-postgres-boilerplate / src / app.ts View on Github external
import express from 'express';
import compression from 'compression';
import bodyParser from 'body-parser';
import cookieParser from 'cookie-parser';

import { ApolloServer, gql } from 'apollo-server-express';
import { importSchema } from 'graphql-import';

import { getResolver } from './graphql/resolvers';
import { db } from './db';

// A map of functions which return data for the schema.
const resolvers = getResolver();
const type = importSchema('./src/graphql/types/schema.graphql');

// The GraphQL schema
const typeDefs = gql`
  ${type}
`;

const apollo = new ApolloServer({
  typeDefs,
  resolvers,
  rootValue: db,
  tracing: true,
});

export const app = express();
apollo.applyMiddleware({ app });
github skmdev / koa-decorator-ts / test / schemas / index.ts View on Github external
import { importSchema } from 'graphql-import';
import { makeExecutableSchema } from 'graphql-tools';
import resolvers from './resolvers';

const typeDefs = importSchema(`${__dirname}/typeDefs.graphql`);

export default makeExecutableSchema({ typeDefs, resolvers });
github LawJolla / prisma-auth0-example / server / src / index.js View on Github external
)
    }
  }
}

const db = new Prisma({
  fragmentReplacements: extractFragmentReplacements(resolvers),
  typeDefs: "src/generated/prisma.graphql",
  endpoint: process.env.PRISMA_ENDPOINT,
  secret: process.env.PRISMA_SECRET,
  debug: true
})

console.log(process.env.PRISMA_ENDPOINT)
const schema = makeExecutableSchema({
  typeDefs: importSchema("./src/schema.graphql"),
  resolvers,
  directiveResolvers
})

const server = new GraphQLServer({
  schema,
  context: req => ({
    ...req,
    db
  })
})

server.express.post(
  server.options.endpoint,
  checkJwt,
  (err, req, res, next) => {
github ctco / nodejs-graphql-template / src / graphql / schema.ts View on Github external
import { makeExecutableSchema } from 'graphql-tools';
import { importSchema } from 'graphql-import';

import resolvers from './resolvers';

const typeDefs: string = importSchema('src/graphql/schema/schema.graphql');

const schema = makeExecutableSchema({
  typeDefs,
  resolvers,
});

export default schema;
github doug2k1 / my-money / src / setupGraphQL.js View on Github external
const setup = app => {
  const path = '/graphql';

  const server = new ApolloServer({
    typeDefs: importSchema('src/graphql/schema.graphql'),
    resolvers,
    playground: { settings: { 'request.credentials': 'include' } },
    context: ({ req }) => {
      return { user: req.user };
    }
  });

  app.use(path, authMiddleware);
  server.applyMiddleware({ app, path });
};

graphql-import

[![Discord Chat](https://img.shields.io/discord/625400653321076807)](https://discord.gg/xud7bH9)

MIT
Latest version published 5 years ago

Package Health Score

50 / 100
Full package analysis

Popular graphql-import functions

Similar packages