graphql-js

GraphQL Schema to handle mixed types

夙愿已清 提交于 2019-12-03 14:24:43
I've recently started to research the possibility of using GraphQL for requesting dynamic data configurations. The very first thing that jumps out at me is the strongly-typed concept of GraphQL. Is there a way for GraphQL schemas to handle arrays of mixed type objects? I would greatly appreciate either an explanation or possibly a reference I can read over. I am currently working with GraphQL with Node.js but a later implementation will be out of a Java Container. All data will be JSON pulled from MongoDB. You either have to make these disparate types implement the same interface, make your

Authorization in GraphQL servers

人走茶凉 提交于 2019-12-03 13:18:13
How to handle Authorization in GraphQL servers? Shall I pass the JWT token in the Authentication header of every requests and check for the authorized user after resolve() and check for the role of user on every query and mutation Introduction First of all, a common approach for authentication as you state is using a signed JWT that contains the id of the user making the request. Now let's have a look at the different parameters we can use when considering the authorization of a given request. who is making the request? determined by the user id mentioned above. More information about the

Authentication in Relay & GraphQL

时光总嘲笑我的痴心妄想 提交于 2019-12-03 03:50:18
I've been working on an application using react and relay, and now I'm stuck on implementing authentication. I know that you can pass value to each graphql request through the context which is available in GraphQL resolves functions. I'm more confused about what to pass for it and how. Is it better to use JSON Web token, passport, something else? And how should I pass the identifier for the user? Basically what I'm asking, What is best suitable for Relay: jwt, passport, something else? And how to hook it up with relay. Thanks! I think your best bet is to study some of the starter kit.

How to setState() in React/Apollo with graphQL

一曲冷凌霜 提交于 2019-12-03 00:42:22
I am trying to setState() to a query result I have from graphQL, but I am having difficulty finding out how to do this because it will always be loading, or it's only used from props. I first set the state constructor (props) { super(props); this.state = { data: [] }; Then I have this query const AllParams = gql` query AllParamsQuery { params { id, param, input } }` And when it comes back I can access it with this.props.AllParamsQuery.params How and when should I this.setState({ data: this.props.AllParamsQuery.params }) without it returning {data: undefined} ? I haven't found a way to make it

Authentication and Access Control with Relay

百般思念 提交于 2019-12-02 18:22:10
The official line from Facebook is that Relay is " intentionally agnostic about authentication mechanisms ." In all the examples in the Relay repository, authentication and access control are a separate concern. In practice, I have not found a simple way to implement this separation. The examples provided in the Relay repository all have root schemas with a viewer field that assumes there is one user. And that user has access to everything. However, in reality, an application has has many users and each user has different degrees of access to each node. Suppose I have this schema in JavaScript

GraphQL Blackbox / “Any” type?

流过昼夜 提交于 2019-12-02 08:33:36
Is it possible to specify that a field in GraphQL should be a blackbox, similar to how Flow has an "any" type? I have a field in my schema that should be able to accept any arbitrary value, which could be a String, Boolean, Object, Array, etc. @mpen's answer is great, but I opted for a more compact solution: const { GraphQLScalarType } = require('graphql') const { Kind } = require('graphql/language') const ObjectScalarType = new GraphQLScalarType({ name: 'Object', description: 'Arbitrary object', parseValue: (value) => { return typeof value === 'object' ? value : typeof value === 'string' ?

Dynamically creating graphql schema with circular references

假如想象 提交于 2019-12-01 09:03:47
By using graphql-js, I need to create graphql schema dynamically by iterating over array of some data, for example: [{ name: 'author', fields: [{ field: 'name' }, { field: 'books', reference: 'book' }] }, { name: 'book', fields: [{ field: 'title' }, { field: 'author', reference: 'author' }] }] The problem is circular references. When I'm creating AuthorType I need BookType to be already created and vise versa. So resulting schema should look like: type Author : Object { id: ID! name: String, books: [Book] } type Book : Object { id: ID! title: String author: Author } How can I solve this?

Dynamically creating graphql schema with circular references

萝らか妹 提交于 2019-12-01 06:39:14
问题 By using graphql-js, I need to create graphql schema dynamically by iterating over array of some data, for example: [{ name: 'author', fields: [{ field: 'name' }, { field: 'books', reference: 'book' }] }, { name: 'book', fields: [{ field: 'title' }, { field: 'author', reference: 'author' }] }] The problem is circular references. When I'm creating AuthorType I need BookType to be already created and vise versa. So resulting schema should look like: type Author : Object { id: ID! name: String,

GraphQL - How to distinguish Public from Private fields?

故事扮演 提交于 2019-12-01 00:50:29
Context I have a GraphQL API and a NodeJS & Angular application with a MongoDB database that holds users. For each user, there is a public page with public information like id and username . When a user is logged in, there is a private profile page with extended information like an email . Just for context, I'm using jsonwebtoken with accesscontrol to authenticate and authorize a user. The information is stored on the Context of every GraphQL resolve function, so whatever is needed to identify a logged in user is available. I have a GraphQL query that retrieves a public user like so: query

Connecting two gatsby nodes

[亡魂溺海] 提交于 2019-11-30 17:51:55
问题 So, I'm using the gatsby-mdx plugin to create a site from MDX files. I want to create an association between the SitePage object and the Mdx object so that I can do one graphQL query of the SitePage edges in order to construct a site navigation. Much of my code is in TypeScript, so ignore any type annotations if you're wondering WTF those are. Things I've tried Using Fields My first thought was to use the onCreateNode API, grab the MDX node, and add it to the SitePage using the