![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
db2graphql
Advanced tools
Generates a Graphql schema and resolvers from an existing relational database
:exclamation::exclamation::exclamation: Warning: don't use this in production yet, but your feedback is very important!
query{
getFirstOfUsers(
filter: "users:id=2"
pagination: "posts:limit=10;orderby=title desc"
) {
id
username
posts {
id
title
categories {
id
title
}
}
}
}
const knex = require('knex');
const db2g = require('db2graphql');
const api = new db2g(knex(require('./connection.json')));
await api.connect();
const schema = api.getSchema();
Example of file connection.json
{
"client": "pg",
"version": "10.6",
"debug": false,
"connection": {
"host" : "127.0.0.1",
"user" : "postgres",
"password" : "postgres",
"database" : "db2graphql"
},
"exclude": []
}
const knex = require('knex');
const db2g = require('db2graphql');
const { ApolloServer, gql } = require('apollo-server');
const start = async (cb) => {
/**************************************/
const api = new db2g(knex(require('./connection.json')));
await api.connect(); // Connects to database and extracts database schema
const schema = api.getSchema();
const resolvers = api.getResolvers();
/**************************************/
// Create Apollo Server and start
if (!schema) throw new Error('Error: empty schema');
console.log(schema);
const server = new ApolloServer({
typeDefs: gql`${schema}`,
resolvers,
});
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});
}
start();
api.override('getFirstOf', async (root, args, context) => {
const { resolver, tablename, db } = context.ioc;
if (tablename === 'categories') return await db('categories').first();
// You can still run the build-in resolver
return resolver.getFirstOf(tablename, args);
});
const db2g = require('db2graphql');
const api = new db2g();
// Add a query and resolver
api.addQuery('getFoo: Boolean');
api.addResolver('Query', 'getFoo', async (root, args, context) => {
return true;
});
// Ready to generate schema
const schema = api.getSchema();
const resolvers = api.getResolvers();
$ git clone https://github.com/taviroquai/db2graphql.git
$ cd db2graphql
$ npm install
$ psql -h localhost -U postgres -c "CREATE DATABASE db2graphql"
$ cp demo/connection.example.json demo/connection.json
# Edit demo/connection.json
$ npm run demo-db
$ npm run start
Open browser on http://localhost:4000 and see your Graphql API ready!
Anyone is free to collab :)
MIT, what else?
FAQs
Generate Graphql schema based on existing relational database
The npm package db2graphql receives a total of 20 weekly downloads. As such, db2graphql popularity was classified as not popular.
We found that db2graphql demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.