
Security News
Open Source Maintainers Feeling the Weight of the EU’s Cyber Resilience Act
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
graphql-tools-builder
Advanced tools
 [](https://codecov.io/gh/mrphu3074/graphql-tools-builder)
Create Graphql schema effortlessly
This library like a plugin for graphql-tools
to organize your modules easier.
const typeDefs = `
scalar Date
type User {
_id: String
username: String
password: String
createdAt: Date
modifiedAt: Date
createdBy: String
modifiedBy: String
creator: User
modifier: User
}
input CreateUserForm {
username: String!
password: String!
}
type Query {
#get all users
getUsers: [User]
}
type Mutation {
#Create new user
createUser(data: CreateUserForm!): User
}
`;
const resolvers = {
User: {
creator(root, args, context) {
if(root.createdBy) {
return context.User.findOne({_id: root.createdBy});
}
return null;
},
modifier(root, args, context) {
if(root.modifiedBy) {
return context.User.findOne({_id: root.modifiedBy});
}
return null;
}
},
Query: {
getUsers(root, args, context) {
return context.User.find({});
}
},
Mutation: {
createUser(root, args, context) {
return context.User.insert(args.data);
}
}
}
import { makeExecutableSchema } from 'graphql-tools';
// Generarte main schema
const schema = makeExecutableSchema({
typeDefs,
resolvers
});
import { makeExecutableSchema } from 'graphql-tools';
import { Schema, Module } from 'graphql-tools-builder';
const GraphqlDate = require('graphql-date);
const schema = new Schema();
const commons = new Module('Commons');
const user = new Module('User');
schema.addModule(commons);
schema.addModule(user);
// set up commons type
commons.createScalar('Date').resolver(GraphqlDate);
// set up user module
user.createType('User')
.field('_id', 'String')
.field('username', 'String')
.field('password', 'String')
.field('createdAt', 'Date')
.field('modifiedAt', 'Date')
.field('createdBy', 'String')
.field('modifiedBy', 'String')
.field('creator', 'User')
.field('modifier', 'User')
.resolver({
creator(root, args, context) {
if(root.createdBy) {
return context.User.findOne({_id: root.createdBy});
}
return null;
},
modifier(root, args, context) {
if(root.modifiedBy) {
return context.User.findOne({_id: root.modifiedBy});
}
return null;
}
});
user.createInput('CreateUserForm')
.field('username', 'String', true)
.field('password', 'String', true);
user.createQuery('getUsers')
.output('[User]')
.resolver((root, args, context) => {
return context.User.find({});
});
user.createMutation('createUser')
.param('data', 'CreateUserForm', true)
.output('User')
.resolver((root, args, context) => ({
return context.User.insert(args.data);
}));
// Generarte main schema
const graphqlSchema = makeExecutableSchema({
typeDefs: schema.getTypeDefs(),
resolvers: schema.getResolvers()
});
FAQs
 [](https://codecov.io/gh/mrphu3074/graphql-tools-builder)
We found that graphql-tools-builder demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.