1.0.1 • Published 6 years ago

import-graphql v1.0.1

Weekly downloads
19
License
MIT
Repository
github
Last release
6 years ago

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
};