Code Monkey home page Code Monkey logo

dgraphql's People

Contributors

dpeek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

dgraphql's Issues

Error: Cannot find module './buildSchema'

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"
  }
}

Give correct input type to reverse edges between different types

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!]!
}

Few Errors (Windows 10 - Dgraph version : v0.8.2)

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
}

Authentication/Authorization/Bussiness logic

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!

Delete node incoming node edges on deletion.

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.

Switch from defining indexes to defining desired filter types.

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.