How to build a web app with GraphQL + parse.com? [closed]

雨燕双飞 提交于 2019-12-05 19:31:39

Yeah, you could certainly build a GraphQL server that was backed by Parse objects!

On the server, you'd build out your GraphQL types as usual; for example, if you had a Todo object and a User object in your Parse Schema (and were using graphql and graphql-relay from npm), you might end up with objects like

// Build the GraphQL Todo type.
var GraphQLTodo = new GraphQLObjectType({
  name: 'Todo',
  fields: () => ({
    content: {
      type: GraphQLString,
      resolve: (obj) => obj.get('content')
    },
    done: {
      type: GraphQLBoolean,
      resolve: (obj) => obj.get('done')
    },
    user: {
      type: GraphQLUser,
      resolve: (obj) => obj.get('user')
    }
  }),
});

// Build the connection from User to Todo
var {connectionType, edgeType} = connectionDefinitions({
  name: 'UserTodo',
  nodeType: GraphQLTodo,
});

// Build the GraphQL User type.
var GraphQLUser = new GraphQLObjectType({
  name: 'User',
  fields: () => ({
    todosConnection: {
      type: connectionType,
      args: connectionArgs,
      resolve: (obj, args) => new Parse.Query(Todo).equalTo('user', obj).find()
    }
  },
});

If the user has signed in on the client, you could potentially pass up a session token to the server to allow for the parse queries to be made with that session token (for ACL reasons).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!