dpeek / dgraphql Goto Github PK
View Code? Open in Web Editor NEWDgraphQL: Build a GraphQL service from a schema
Home Page: http://dpeek.com/dgraphql
License: Other
DgraphQL: Build a GraphQL service from a schema
Home Page: http://dpeek.com/dgraphql
License: Other
https://tour.dgraph.io/intro/3/
Facets and Aggregation https://docs.dgraph.io/query-language/#facets-and-aggregation
mutation {
schema {
name: string @index(exact, term) .
age: int @index(int) .
friend: uid @count .
Reputation: int @index(int)
}
If I need to count how many partners, children, parents or friends How to proceed?
Using the Dgraph feature of counting.
Cheers
I'm getting this error when I try to run something similar to the example. Apologies if this if a support request and not a bug report… I could certainly be doing something wrong. Thank you!
Here's my server.js
:
#!/usr/bin/env node
const path = require('path');
const fs = require('fs');
const express = require('express');
const graphqlHTTP = require('express-graphql');
const { Client } = require('dgraphql');
const schema = path.resolve(__dirname, 'data', 'schema.graphql');
const client = new Client({
server: 'http://localhost:8080/query',
schema: fs.readFileSync(schema, 'utf-8'),
});
const app = express();
app.use('/', graphqlHTTP((req, res) => {
const lang = req.headers['accept-language'].split('-')[0];
return {
schema: client.schema,
context: client.getContext(lang),
graphiql: true,
};
}));
app.listen(4000);
Here's the output:
$ ./server.js
module.js:487
throw err;
^
Error: Cannot find module './buildSchema'
at Function.Module._resolveFilename (module.js:485:15)
at Function.Module._load (module.js:437:25)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (.../node_modules/dgraphql/lib/client.js:18:20)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
And here's my package.json
:
{
"dependencies": {
"dgraphql": "^0.4.0",
"express": "^4.15.3",
"express-graphql": "^0.6.6",
"graphql": "^0.10.3"
}
}
Example:
type User {
id: ID!
groups: [Group!] @reverse(name: "members")
}
type Group {
id: ID!
members: [User!] @reverse(name: "groups")
}
Currently, this creates a type
type AddUserGroupsMutationInput {
id: ID!
groups: [UserInput!]!
}
When it should create
type AddUserGroupsMutationInput {
id: ID!
groups: [GroupInput!]!
}
Create, update, add and set mutations should check the type of existing nodes when mutating edges.
Hello,
I pass the example schema to new Client
, then printSchema(client.schema)
, and send the result to relay-compiler, which throws the error. Any help would be appreciated.
Have you given up on this project?
Test Suites: 7 failed, 7 total
Tests: 68 failed, 68 total
Snapshots: 0 total
Time: 9.152s
Ran all test suites.
---------------------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
---------------------|----------|----------|----------|----------|----------------|
All files | 55.43 | 43.46 | 56.3 | 55.95 | |
src | 81.61 | 69.91 | 80.26 | 81.96 | |
buildSchema.js | 100 | 100 | 100 | 100 | |
client.js | 84.21 | 64 | 88.89 | 84.21 |... 57,59,64,87 |
getInfo.js | 94 | 83.33 | 100 | 93.88 | 85,116,127 |
getResolvers.js | 87.5 | 78.57 | 75 | 92.86 | 33,36,37 |
transformSchema.js | 92.04 | 78 | 94.87 | 91.67 |... 729,742,752 |
utils.js | 25 | 18.52 | 38.89 | 23.08 |... 136,137,139 |
src/mutate | 39.6 | 28.74 | 48.39 | 41.13 | |
create.js | 80.77 | 70 | 77.78 | 91.3 | 25,39 |
delete.js | 0 | 0 | 0 | 0 |... 54,58,59,61 |
edge.js | 0 | 0 | 0 | 0 |... 71,74,75,78 |
getMutation.js | 82.61 | 60 | 100 | 88.1 | 82,83,84,87,88 |
remove.js | 0 | 0 | 0 | 0 |... 30,33,34,35 |
src/query | 0 | 0 | 0 | 0 | |
connection.js | 0 | 0 | 0 | 0 |... 29,33,34,35 |
getSelections.js | 0 | 0 | 0 | 0 |... 197,201,212 |
id.js | 0 | 100 | 0 | 0 | 6 |
list.js | 0 | 0 | 0 | 0 | 15,16,17,18 |
node.js | 0 | 0 | 0 | 0 | 15,16,17,18,19 |
payload.js | 0 | 0 | 0 | 0 |... 40,41,42,43 |
query.js | 0 | 0 | 0 | 0 |... 31,33,41,42 |
src/scalar | 0 | 0 | 0 | 0 | |
GraphQLDateTime.js | 0 | 0 | 0 | 0 |... 13,14,15,18 |
GraphQLJSON.js | 0 | 100 | 0 | 0 | 11,12,14 |
---------------------|----------|----------|----------|----------|----------------|
error Command failed with exit code 1.
-- dgraph query
mutation { schema {
__typename: string @index(hash) .
dob: datetime @index(datetime) .
lastActiveAt: datetime @index(datetime) .
name: string @index(exact,term) .
title: string @index(exact) .
employed: bool @index(bool) .
time: int @index(int) .
age: int @index(int) .
height: float @index(float) .
partner: uid .
children: uid .
parents: uid .
createdAt: datetime @index(datetime) .
updatedAt: datetime @index(datetime) .
type: string @index(exact) .
}}
--dgraph response
{
"errors": [
{
"code": "Error",
"message": "failed to parse schema error: invalid request: Invalid tokenizer datetime"
}
],
"data": null
}
-- dgraph query
query {
people(func:eq(__typename, "Person")) {
_uid_
__typename
}
}
--dgraph response
{
"errors": [
{
"code": "Error",
"message": "Attribute __typename is not indexed."
}
],
"data": null
}
-- dgraph query
query { nodes(id: []) { _uid_, __typename }}
--dgraph response
{
"errors": [
{
"code": "ErrorInvalidRequest",
"message": "Got invalid keyword: id at root"
}
]
}
-- dgraph query
mutation { set {
_:node <__typename> "Person" .
_:node <name> "David" .
_:node <createdAt> "2017-09-23T22:27:18.437Z" .
_:node <updatedAt> "2017-09-23T22:27:18.437Z" .
}}
--dgraph response
{
"data": {
"code": "Success",
"message": "Done",
"uids": {
"node": "0xea62"
}
}
}
-- dgraph query
query { nodes(id: []) { _uid_, __typename }}
--dgraph response
{
"errors": [
{
"code": "ErrorInvalidRequest",
"message": "Got invalid keyword: id at root"
}
]
}
-- dgraph query
mutation { set {
_:node <__typename> "Person" .
_:node <name> "Michel Conrado" .
_:node <title> "Sir"@pt .
_:node <employed> "false" .
_:node <age> "28" .
_:node <createdAt> "2017-09-23T22:28:03.297Z" .
_:node <updatedAt> "2017-09-23T22:28:03.297Z" .
}}
--dgraph response
{
"data": {
"code": "Success",
"message": "Done",
"uids": {
"node": "0xea63"
}
}
}
-- dgraph query
query {
people(func:eq(__typename, "Person")) {
_uid_
__typename
}
}
--dgraph response
{
"errors": [
{
"code": "Error",
"message": "Attribute __typename is not indexed."
}
],
"data": null
}
Hello,
I like how easy it is to get a working GraphQL backend-data service with this project.
I'd like to test this on a small production project, but before I do, I'd like to find a way to solve some common issues:
1. Authentication
I guess this could be implemented as an express (connect-type) authentication middleware, that would first read JWT, make a dgraph query for a user, and then put authenticated user to the graphql context.
2. Authorization
Let's say we have an authenticated user (and his role) in a graphql context. How would I restrict certain users from reading/manipulating data that should be restricted to them?
I know I can make my own mutations/queries with custom logic, but I would loose all the nice features of the auto-generated queries/mutations.
3. Bussiness logic
Let's say I wan't to send an email after creating a user (after performing a createUser mutation). Where would I put this "send email" logic?
I really have no clue how I would solve this. Maybe some kind to extend some of the auto-generated queries/mutations with custom "hooks"?
Thanks for any suggestion or answer!
Dgraph doesn't clean up references to nodes upon deletion – there is an empty subject with no predicates that is still referenced by other nodes.
So, we'll have to clean things up ourselves. Basically query all incoming edges before deletion and delete those too in the delete mutation.
Right now we specify which dgraph indexes we want on properties:
type Person {
id: ID!
name: String @index(type: "exact")
}
It would be nicer if instead we specified how we want to filter properties:
type Person {
id: ID!
name: String @filter(type: EQ) @filter(type: TERM)
}
Users then don't have to think about the dgraph index required (bool, int, float etc) and we can only generate the filters that they want.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.