import-graphql
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

import-graphql

Install

NPM

npm install import-graphql --save

YARN

yarn add import-graphql

Usage

defs.ts

import { importSchema } from 'import-graphql';
import * as path from 'path';
 
const schema = importSchema(path.join(__dirname, 'types'));
 
export default schema;
 

Assume the following directory structure:

types/
├── schema.graphql
└── message.graphql

schema.graphql

schema {
    query: Query
}
 
type Query {
  messages: [Message]
}
 
type Mutation {
  mark_read_all: ResponseStatus!
}
 
type ResponseStatus {
  status: Boolean!
}
 

message.graphql

type Message {
  id: String!
  title: String!
  content: String!
}
extend type Mutation {
  create_message(
    title: String!
    content: String!
  ): Message
}
 

schema.ts

import defs from './defs';
import { makeExecutableSchema } from 'apollo-server';
 
const schema = makeExecutableSchema({
    typeDefs: defs,
    resolverValidationOptions: {
        requireResolversForResolveType: false
    }
});
 
export {
    schema
};

Dependencies (0)

    Dev Dependencies (2)

    Package Sidebar

    Install

    npm i import-graphql

    Weekly Downloads

    18

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    3.63 kB

    Total Files

    5

    Last publish

    Collaborators

    • chanhsa