Giter Club home page Giter Club logo

genie-team / graphql-genie Goto Github PK

View Code? Open in Web Editor NEW
165.0 165.0 15.0 7.09 MB

Simply pass in your GraphQL type defintions and get a fully featured GraphQL API with referential integrity, inverse updates, subscriptions and role based access control that can be used client side or server side.

Home Page: https://genie-team.github.io/graphql-genie-client/

License: MIT License

JavaScript 3.48% TypeScript 96.52%
api database genie graphql graphql-subscriptions progressive-web-app pwa serverless

graphql-genie's People

Contributors

acoreyj avatar adamdbradley avatar brandyscarney avatar coreyentropy avatar dependabot[bot] avatar ecwyne avatar gvhuyssteen avatar jerrygreen avatar jgw96 avatar kaihaase avatar manucorporat avatar mhartington avatar nikolasburk avatar timmikeladze 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

graphql-genie's Issues

[Question/Bug] Allowing for Schema Evolution

I am trying to figure out if I am able to change my schema over time. As a test I ran the following schema

interface Human {
  id: ID!
  name: String
}

type Boy implements Human {
  id: ID!
  name:String!
  sisters: [Girl]!
}

type Girl implements Human {
  id: ID!
  name:String!
  brothers: [Boy]!
}

(Using IndexedDB) I see that a Boy_Girl_Human table is created and items have a Boy_Girl_Human_[id] structure.

Adding the following to my schema (not changing the other types at all)

type Father implements Human {
  id: ID!
  name: String!
  sons: [Boy]!
}

A Boy_Father_Girl_Human table is created and items have a Boy_Father_Girl_Human_[id] structure. This actually breaks https://genie-team.github.io/graphql-genie-client and queries/mutations do not go through at all (until I delete the IndexedDB)

How can I structure things to be able to make changes to my schema definition without breaking my database?

CRUD permission on fields?

(Please label as question)

Just a quick question, is there any reason to set create and delete permissions on individual fields? Maybe the field is nullable and create/delete are adding a value or setting it to null? What is your experience?

An error occurs when using scalars

Describe the bug
If you use your own scalars, an error occurs. Even if the type was not declared as a @model:

 Error: The value for "link" on "NAME_OF_THE_FIELD" in type "NAME_OF_THE_TYPE" is invalid, the record type does not exist.

To Reproduce

GraphQL:

typeDefs: `
   ...
    "Scalar for any (JSON) value"
    scalar Any
   ...
   "Information about the API"
    type API {
     
      "Environment of the API"
      environment: String!
      
      "Name of the API"
      name: String!
      
      "Current version of API"
      version: String!
      
      "Current Position"
      ipLookup: Any @deprecated(reason: "May be to much information")
    }
   ...
`,

resolvers: {

    /** Resolver for any (JSON) */
    Any: YosAnyScalar,
   ...
}

Resolvers are added via mergeSchemas after the initialization of GraphQLGenie.

Scalar:

import { GraphQLScalarType } from 'graphql';

/**
 * Any scalar type for GraphQL
 * Inspired by https://github.com/taion/graphql-type-json
 *
 * @type {GraphQLScalarType}
 */
export const YosAnyScalar = new GraphQLScalarType({

  /**
   * Name of the scalar
   */
  name: 'Any',

  /**
   * Description of the scalar
   */
  description: 'The `Any` scalar represents JSON values as specified by ' +
    '[ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf).',

  /**
   * Parse value from the client
   * @param value
   * @returns {any}
   */
  parseValue(value: any): any {
    return value;
  },

  /**
   * Serialize value to the client
   * @param value
   * @returns {any}
   */
  serialize(value: any): any {
    return value;
  },

  /**
   * Parse literal
   * @param valueNode
   * @param variables
   * @returns {any}
   */
  public static parseLiteral(valueNode: ValueNode, variables?: Maybe<YosObject>): any {
    switch (valueNode.kind) {
      case Kind.STRING:
      case Kind.BOOLEAN:
        return valueNode.value;
      case Kind.INT:
      case Kind.FLOAT:
        return parseFloat(valueNode.value);
      case Kind.OBJECT: {
        const value = Object.create(null);
        valueNode.fields.forEach(field => {
          value[field.name.value] = YosGraphQL.parseLiteral(field.value, variables);
        });
        return value;
      }
      case Kind.LIST:
        return valueNode.values.map(n => YosGraphQL.parseLiteral(n, variables));
      case Kind.NULL:
        return null;
      case Kind.VARIABLE: {
        const name = valueNode.name.value;
        return variables ? variables[name] : undefined;
      }
      default:
        return undefined;
    }
  }
});

Error:

 Error: The value for "link" on "ipLookup" in type "API" is invalid, the record type does not exist.
  • Genie Version [0.4.17]
  • Fortune Adapter [MongoDB]

Expected behavior
No error

Upsert fails silently

Working example: https://codesandbox.io/s/graphql-genie-upsert-issue-yckp9

  • IDL
  • Genie Version 0.4.24
  • Fortune Adapter fortune-indexeddb 1.1.2

Schema:

type Item {
  id: ID!
  user: User!
  content: String!
}

type User {
  id: ID!
  name: String! @unique
  fullName: String!
  created: DateTime @createdTimestamp
}

Mutation:

mutation {
  createItem(
    input: {
      data: {
        user: {
          upsert: {
            create: { name: "test" }
            update: { fullName: "Test T." }
            where: { name: "test" }
          }
        }
        content: "Lorem ipsum"
      }
    }
  ) {
    data {
      id
      user {
        name
        fullName
      }
      content
    }
  }
}

The upsert fails silently and the user is not inserted.

Graphql yoga PostgreSQL example not starting up

Describe the bug
Starting the server in the graphql yoga example (https://github.com/genie-team/graphql-genie/tree/master/examples/graphql-yoga-postgresql) results in Cannot find module 'graphql' webpack error for graphql-genie-subscriptions.

This is the error message seen:

`$ npm run start

[email protected] start /Users/nstudy/projects/graphql-genie/examples/graphql-yoga-postgresql
node dist/index.js

webpack:///./node_modules/graphql-genie-subscriptions/lib_sync?:4
throw e;
^

Error: Cannot find module 'graphql'
at webpackEmptyContext (webpack:///./node_modules/graphql-genie-subscriptions/lib_sync?:2:10)
at eval (webpack:///./node_modules/graphql-genie-subscriptions/lib/subscriptions.js?:23:23)
at eval (webpack:///./node_modules/graphql-genie-subscriptions/lib/subscriptions.js?:11:17)
at eval (webpack:///./node_modules/graphql-genie-subscriptions/lib/subscriptions.js?:20:3)
at Object../node_modules/graphql-genie-subscriptions/lib/subscriptions.js (/Users/nstudy/projects/graphql-genie/examples/graphql-yoga-postgresql/dist/index.js:2234:1)
at webpack_require (/Users/nstudy/projects/graphql-genie/examples/graphql-yoga-postgresql/dist/index.js:20:30)
at eval (webpack:///./src/main.ts?:6:85)
at Module../src/main.ts (/Users/nstudy/projects/graphql-genie/examples/graphql-yoga-postgresql/dist/index.js:5974:1)
at webpack_require (/Users/nstudy/projects/graphql-genie/examples/graphql-yoga-postgresql/dist/index.js:20:30)
at /Users/nstudy/projects/graphql-genie/examples/graphql-yoga-postgresql/dist/index.js:84:18
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: node dist/index.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/nstudy/.npm/_logs/2018-09-04T21_44_20_324Z-debug.log
`

To Reproduce
Used node 8.11.4 LTS and npm 5.6.0

  • cd examples/graphql-yoga-postgresql
  • npm install
  • npm run build
  • npm run start

Attached is my package-lock.json file as a text file.
package-lock.json.txt

Expected behavior
Server should have started up without errors.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):
Using MacOS Sierra 10.12.6

Additional context
Add any other context about the problem here.

[Question] Order of schema?

Using the example schema provided.

interface Submission {
	id: ID! @unique
	text: String!
	author: User @relation(name: "SubmissionsByUser")
}

type Story implements Submission @model {
	id: ID! @unique
	title: String!
	text: String!
	author: User @relation(name: "SubmissionsByUser")
	likedBy: [User!] @connection @relation(name: "LikedSubmissions")
}

type Comment implements Submission @model {
	id: ID! @unique
	text: String!
	author: User @relation(name: "SubmissionsByUser")
	approved: Boolean @default(value: "true")
}

type User @model {
	id: ID! @unique
	email: String @unique
	submissions: [Submission!] @relation(name: "SubmissionsByUser")
	address: Address
	liked: [Submission!] @connection @relation(name: "LikedSubmissions")
	createdAt: DateTime @createdTimestamp
	lastUpdatedAt: DateTime @updatedTimestamp
}

type Address @model {
	id: ID! @unique
	city: String!
	user: User
}

If I put the User type before the Submission interface (everything else is held constant)

type User @model {
	id: ID! @unique
	email: String @unique
	submissions: [Submission!] @relation(name: "SubmissionsByUser")
	address: Address
	liked: [Submission!] @connection @relation(name: "LikedSubmissions")
	createdAt: DateTime @createdTimestamp
	lastUpdatedAt: DateTime @updatedTimestamp
}

interface Submission {
	id: ID! @unique
	text: String!
	author: User @relation(name: "SubmissionsByUser")
}

type Story implements Submission @model {
	id: ID! @unique
	title: String!
	text: String!
	author: User @relation(name: "SubmissionsByUser")
	likedBy: [User!] @connection @relation(name: "LikedSubmissions")
}

type Comment implements Submission @model {
	id: ID! @unique
	text: String!
	author: User @relation(name: "SubmissionsByUser")
	approved: Boolean @default(value: "true")
}

type Address @model {
	id: ID! @unique
	city: String!
	user: User
}

I get the following errors

Bad schema, relation could apply to multiple fields
 relation name SubmissionsByUser
 fortune name User
 curr field author
 other field submissions
Bad schema, relation could apply to multiple fields
 relation name SubmissionsByUser
 fortune name User
 curr field author
 other field submissions
Bad schema, relation could apply to multiple fields
 relation name SubmissionsByUser
 fortune name User
 curr field author
 other field submissions
Bad schema, relation could apply to multiple fields
 relation name SubmissionsByUser
 fortune name User
 curr field author
 other field submissions

Do I always need to put interfaces before types?

Default export not working for plugins

import auth from 'graphql-genie-authentication'; // undefined
import subs from 'graphql-genie-subscriptions'; // undefined

import * as auth from 'graphql-genie-authentication';  // [Function: authentication]
import * as subs from 'graphql-genie-subscriptions'; // [Function: subscriptions]

I think this has something to do with the rollup configuration (from what I can tell)

Memory example not working with latest graphql-tools

The memory example uses rollup, unfortunately the latest graphql-tools has circular dependencies that result in bad js for the browser.

I opened an issue at graphql tools as well. ardatan/graphql-tools#924

The fix was to downgrade the graphql-tools version which makes the memory example work, opened this issue so it can be upgraded if this is fixed in the future.

Unexpected Non-Nullable List Behavior

Describe the bug
Given the schema below, I am unable to create a User with an empty posts list. Either a posts.create or posts.connect is required for the mutation. Perhaps a posts.empty would do the trick.

To Reproduce

# typeDefs
type User @model {
  id: ID!
  name: String!
  posts: [Post]! @relation(name: "author")
}

type Post @model {
  id: ID!
  content: String!
  authors: User! @relation(name: "author")
}
# mutation
mutation {
  createUser(input: {data: {name: "Eric"}}) {
    data {
      name
      posts {
        content
      }
    }
  }
}
  • Genie Version: 0.3.5
  • Fortune Adapter: In Memory

Expected behavior
I would expect to create a User with posts: [].

Additional context
I realize I can have the list as Nullable, however I think that posts: [] is a much more sensible response than posts: null (then I have to check if posts exists before using it every time)

Is amazing graphql-genie production ready?

@acoreyj Thanks for creating such an amazing project. This project has a great potential to make developers life easy. I want to use graphql-genie with sapperjs https://sapper.svelte.technology/ and mongodb for my new project but I have few concerns

  • Is graphql-genie production ready?
  • Is there any roadmap for future development?
  • Graphql has n+1 request problem and fortunejs mongodb adptor is using multiple find statements for related documents which means multiple database roundtrip fortunejs/fortune-mongodb#21 (comment). Performance of Nested queries is my main concern. Other similar projects like https://www.graphile.org/graphile-build/look-ahead/ are using single database query for nested graphql queries. We can try to convince fortunejs author to use single mongodb aggregation pipeline with $lookup operator for finding the related documents to avoid multiple database roundtrips but ideally, a great project like graphql-genie shouldn't be dependent on any third party module for data access. I know its lots of work but I think it will greatly improve query performance. Fortunejs mongodb adapter is also lacking support for transactions and data aggregations.

We should have a project/documentation website for such an amazing project and a discoed server for community support.

Expandable Fortune.js store

It would be useful to be able to extend and use the Fortune.js store outside of GraphQL Genie or to pass an already created store to GraphQL Genie.

[ Support Question ] The value for inverse... is invalid

Can you help me figure out what this error means?

      "message": "The value for \"inverse\" on \"post\" in type \"Comment\" is invalid, the inversely related field must define its inverse as \"post\".",

My schema looks like this:

type Comment {
  id: ID! @unique
  createdAt: DateTime @createdTimestamp
  updatedAt: DateTime @updatedTimestamp
  author: User @relation(name: "commentsByUser")
  body: String
  post: Post @relation(name: "commentsOnPost")
}

enum postType {
  TEXT
  LINK
}

type Post {
  id: ID! @unique
  createdAt: DateTime @createdTimestamp
  updatedAt: DateTime @updatedTimestamp
  author: User @relation(name: "postsByUser")
  type: postType
  comments: [Comment!] @relation(name: "commentsOnPost")
}

type User {
  id: ID! @unique
  createdAt: DateTime @createdTimestamp
  updatedAt: DateTime @updatedTimestamp
  userName: String! @unique
  posts: [Post!] @relation(name: "postsByUser")
  comments: [Comment!] @relation(name: "commentsByUser")
}

Am I not defining my relations correctly?

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.