Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
graphql-genie
Advanced tools
Write a GraphQL Type Schema and GraphQL Genie turns it into a fully featured GraphQL API with referential integrity and inverse updates that can be used client side or server side. You can use all the features of the type schema, including interfaces and unions. Add subscriptions with the plugin. The schema uses best practices and is compliant with the Relay GraphQL Server Specification.
Because GraphQL Genie gives you a fully functioning schema but is not opinionated about anything else you have flexibility to use that schema wherever you want and integrate it was any existing services you use. You can use The Apollo Platform, Relay (https://facebook.github.io/relay/) or any of the many other tools in the growing GraphQL ecosystem. You can use your existing authentication methods or one provided by an outside service.
Assuming you already have GraphQL Genie installed.
npm install graphql-genie fortune graphql graphql-tools lodash
or yarn add graphql-genie fortune graphql graphql-tools lodash
Create your type defintions.
Genie will compute relations for referential integrity and inverse updates (like between User and Address below) but if the relation is ambiguous the @relation directive should be used
interface Submission {
id: ID! @unique
text: String!
author: User @relation(name: "SubmissionsByUser")
}
type Story implements Submission {
id: ID! @unique
title: String!
text: String!
author: User @relation(name: "SubmissionsByUser")
likedBy: [User]
}
type Comment implements Submission {
id: ID! @unique
text: String!
author: User @relation(name: "SubmissionsByUser")
}
type User {
id: ID! @unique
email: String @unique
submissions: [Submission!]! @relation(name: "SubmissionsByUser")
address: Address
}
type Address {
id: ID! @unique
city: String!
user: User
}
Setup fortune options (see fortune docs](http://fortune.js.org/api/#fortune-constructor) and then create the schema using genie.
import { FortuneOptions, GraphQLGenie } from 'graphql-genie';
import mongodbAdapter from 'fortune-mongodb';
//adapter: configuration array for the data store. The default type is the memory adapter. See below for other adapter options
const fortuneOptions: FortuneOptions = {
adapter: [
mongodbAdapter,
{
// options object, URL is mandatory.
url: config.mongodbURL
}
],
settings: { enforceLinks: true }
};
// Instantiate Genie with your type defintions
const typeDefs = `[TYPEDEFS]`
const genie = new GraphQLGenie({
typeDefs: typeDefs,
fortuneOptions: fortuneOptions,
generatorOptions: {
generateGetAll: true,
generateCreate: true,
generateUpdate: true,
generateDelete: true,
generateUpsert: true
}
});
// init genie, this sets up all the new types and resolvers, init returns a promise so use await or .then()
await genie.init();
// get the schema and use it with any other tools you want
const schema: GraphQLSchema = genie.getSchema();
GraphQLGenie uses FortuneJS for accessing the data store. This means any fortune adapter will work, plugins currently exist for memory (example), IndexedDB (example), MongoDB (example), Postgres (example), Redis, Google Cloud Datastore, NeDB and File System. Or you could write your own.
GraphQL Genie also supports subscriptions with the subscriptions plugin.
Pass in a plugin that alters the schema, see the subscriptions plugin for an example
See info about the GeniePlugin interface in GraphQLGenieInterfaces.ts
Get the schema
Return a string of the full schema with directives
When using Apollo or another tool you may need to get information on the fragment types, genie provides a helper for this
import { IntrospectionFragmentMatcher, IntrospectionResultData } from 'apollo-cache-inmemory';
const introspectionQueryResultData = <IntrospectionResultData>await genie.getFragmentTypes();
const fragmentMatcher = new IntrospectionFragmentMatcher({
introspectionQueryResultData
});
DataResolver handles all the operations with your actual data. Such as CRUD and hooks.
Most likely use of this is to add hooks into the CRUD operations against your database. The DataResolver has 2 functions to add hooks. For more info on the context, record and update objects see the fortune documentation.
interface DataResolverInputHook {
(context?, record?, update?): any;
}
interface DataResolverOutputHook {
(context?, record?): any;
}
addOutputHook(graphQLTypeName: string, hook: DataResolverOutputHook);
addInputHook(graphQLTypeName: string, hook: DataResolverInputHook);
See info about the DataResolver interface in GraphQLGenieInterfaces.ts
GraphQLSchemaBuilder has some additional helpers to add types and resolvers to a graphql schema
See info about the GraphQLSchemaBuilder interface in GraphQLGenieInterfaces.ts
Additional documentation is in development, see examples and tests for implementation examples.
Work is in progress on a plugin to make it extremely easy to add Authentication to a schema created with GraphQL Genie. There are a lot of ways to have some sort of authentication with a GraphQL API and Genie gives you the flexibility to do it any way you want or integrate into services such as Auth0 or Firebase.
Some options to add authentication
Prisma GraphQL / Graphcool for inspiration
FortuneJS for CRUD adapters
Logo Icon made by Freepik from www.flaticon.com is licensed by CC 3.0 BY
FAQs
GraphQL Genie
The npm package graphql-genie receives a total of 9 weekly downloads. As such, graphql-genie popularity was classified as not popular.
We found that graphql-genie 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
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.