Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@backref/graphql-to-json-schema
Advanced tools
Transform a GraphQL Schema introspection file to a valid JSON Schema.
Transform a GraphQL Schema introspection file to a valid JSON Schema.
This package adds support for decorators improving the utility of GraphQL schema as an IDL for everything.
Decorators, aka annotations or attributes in other languages, allows metadata to be attached to GraphQL schema entities. The decorator metadata appear as properties in the resulting JSON schema. Decorator metadata can be used for validations, ACL roles, code generation, form generation ...
The syntax is simple
# decorator with map value
+go_tag({"json": "id", "db": "id"})
# truthy decorator, empty parens default to true
+read_only()
+read_only(false)
# array
+acl_roles(["session", "admin"])
# string
+go_ident("ID")
# number (int, float, etc)
+form_pos(1)
Decorator rules
""
description or docstring+
symbol to disambiguate against @
directives()
is converted to boolean value of true
.Decorators example in GraphQL schema
type Todo {
"""
The primary key.
+read_only()
+go_ident("ID")
+go_tag({"db": "id", "json": "id,omitempty"})
"""
id: String!
name: String!
completed: Boolean
}
The result JSON schema is enriched with __decorators
property
Todo: {
type: 'object',
properties: {
id: {
__decorators: {
go_ident: "ID",
go_tag: {db:"id", json: "id,omitempty"},
read_only: true
},
description: 'The primary key',
type: 'string'
},
name: { type: 'string' },
completed: { type: 'boolean' },
},
required: ['id', 'name']
}
To use the gql2js
CLI utility, first install the package
yarn global add @backref/graphql-to-json-schema
# OR
npm install -g @backref/graphql-to-json-schema
Running the utility
# output to STDOUT
gql2js example/example.graphql
# output to file
gql2js example/example.graphql -o example.json
# output to directory (use single quotes)
gql2js 'example/**/*.graphql' -d _temp
Programmatic
yarn add @backref/graphql-to-json-schema
// node example
const g2j = require('@backref/graphql-to-json-schema');
const text = `
type Todo {
"""
The primary key.
+read_only()
+go_ident("ID")
+go_tag({"db": "id", "json": "id,omitempty"})
"""
id: String!
name: String!
completed: Boolean
}
`;
const jsonSchema = g2j.parseGraphQL(text);
console.log(JSON.stringify(jsonSchema, null, 2));
This package is MIT licensed
Original work by
Enhancements by
FAQs
Transform a GraphQL Schema introspection file to a valid JSON Schema.
The npm package @backref/graphql-to-json-schema receives a total of 1 weekly downloads. As such, @backref/graphql-to-json-schema popularity was classified as not popular.
We found that @backref/graphql-to-json-schema 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.