
Product
Introducing Supply Chain Attack Campaigns Tracking in the Socket Dashboard
Campaign-level threat intelligence in Socket now shows when active supply chain attacks affect your repositories and packages.
graphql-schema-gen
Advanced tools
Generate JavaScript GraphQL schema from the GraphQL language
npm install graphql-schema-gen
var createQueryFn = require('graphql-schema-gen');
var query = createQueryFn(`
scalar Date
union Animal =
Cat |
Dog
enum Role {
# Means a user has full administrative access to everything
Admin
# Means a user has ability to moderate comments
Moderator
# Means a user has read only access
None
}
type Cat {
nightVision: String
}
type Dog {
woof: String
}
interface Node {
id: ID!
}
# A type to represent a person
type Person implements Node {
id: GlobalID
name: String
dateOfBirth: Date
role: Role
friends(): [Person]!
pet(): Animal
hello(name: String = "World"): String
}
type Query {
me(): Node
}
`, {
Date: {
serialize(value) {
return /^\d\d\d\d\-\d\d\-\d\d$/.test(value) ? value : null;
},
parse(value) {
return /^\d\d\d\d\-\d\d\-\d\d$/.test(value) ? value : null;
}
},
Node: {
resolveType(node, info) {
return info.schema.getType(node.type);
}
},
Animal: {
resolveType(node, info) {
return info.schema.getType(node.type);
}
},
Query: {
me() {
return {name: 'Forbes Lindesay', dateOfBirth: '1830-06-11', role: 'Admin', type: 'Person'};
}
},
Person: {
id(obj) {
return obj.name;
},
pet() {
return {
woof: 'Woof Woof!',
type: 'Dog'
};
},
friends() {
return [{name: 'jonn', dateOfBirth: 'whatever', role: 'None', type: 'Person'}];
},
hello(person, {name}, context) {
return 'Hello ' + name;
}
}
});
query(`
{
me {
id
...on Person {
role
dateOfBirth
name,
friends { id, name, dateOfBirth, role }
pet { ...on Dog {woof}}
hello
helloForbes: hello(name: "Forbes")
}
}
}
`, {}).then(function (result) {
if (result.errors) {
setTimeout(() => { throw result.errors[0]; }, 0);
}
console.dir(result, {colors: true, depth: 100});
});
MIT
FAQs
Generate JavaScript GraphQL schema from the GraphQL language
We found that graphql-schema-gen 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.

Product
Campaign-level threat intelligence in Socket now shows when active supply chain attacks affect your repositories and packages.

Research
Malicious PyPI package sympy-dev targets SymPy users, a Python symbolic math library with 85 million monthly downloads.

Security News
Node.js 25.4.0 makes require(esm) stable, formalizing CommonJS and ESM compatibility across supported Node versions.