2017-04-24 1 views
0

내 keystone.js 앱 (Express 미들웨어 express-graphql 통해) 용 GraphQL 끝점을 만들지 않았습니다. keystone.js에서 파일 형식으로 구현 현장 사진Keystone이 필요한 GraphQL은 출력 유형이어야하지만 : undefined

const keystone = require('keystone'); 

const Types = keystone.Field.Types; 

const User = new keystone.List('User'); 

const localStorage = new keystone.Storage({ 
    adapter: keystone.Storage.Adapters.FS, 
    fs: { 
    path: './src/upload/avatars', 
    publicPath: '/upload/avatars', 
    }, 
}); 

User.add({ 
    name: { type: Types.Name, required: true, index: true }, 
    email: { type: Types.Email, initial: true, index: true }, 
    password: { type: Types.Password, initial: true, required: true }, 
}, 'Profile', { 
    photo: { type: Types.File, storage: localStorage }, 
}, 'Permissions', { 
    isAdmin: { type: Boolean, label: 'Can access Keystone', index: true }, 
}, 
); 

// Provide access to Keystone 
User.schema.virtual('canAccessKeystone').get(function() { 
    return this.isAdmin; 
}); 

User.defaultColumns = 'name, email, isAdmin'; 
User.register(); 

핵심 문제 :

여기 내 키스톤 스키마입니다. 내 GraphQL 스키마 아래

:

import { GraphQLSchema, GraphQLID, GraphQLList, GraphQLNonNull, GraphQLObjectType, } from 'graphql'; 

const keystoneTypes = require('keystone-graphql').Types; const keystone = require('keystone'); 

const User = keystone.list('User'); 

const userType = new GraphQLObjectType({ name: 'User', fields:() 
=> ({ 
    id: { type: new GraphQLNonNull(GraphQLID) }, 
    name: { type: new GraphQLNonNull(keystoneTypes.Name(User.fields.name)) }, 
    email: keystoneTypes.Email(User.fields.email), 
    photo: keystoneTypes.File(User.fields.photo), }), }); 

const queryRootType = new GraphQLObjectType({ name: 'Query', fields: { 
    users: { 
     type: new GraphQLList(userType), 
     resolve:() => 
     User.model.find().exec(), 
    }, 
    user: { 
     type: userType, 
     args: { 
     id: { 
      description: 'id of the user', 
      type: new GraphQLNonNull(GraphQLID), 
     }, 
     }, 
     resolve: (_, args) => User.model.findById(args.id).exec(), 
    }, }, }); 

export default new GraphQLSchema({ query: queryRootType, }); 

그리고 갈래 키스톤 - graphql 패키지에 포함 된 필드 파일 구현 :

내가 가진 패키지 graphql을 키스톤을 끌어 오기 요청을 할
'use strict'; 

const GraphQL = require('graphql'); 

const KeystoneFileType = new GraphQL.GraphQLObjectType({ 
    name: 'KeystoneFile', 
    fields: { 
    size: { type: GraphQL.GraphQLInt }, 
    mimetype: { type: GraphQL.GraphQLString }, 
    filename: { type: GraphQL.GraphQLString }, 
    }, 
}); 

module.exports = (field) => KeystoneFileType; 

파일 필드가 제대로 작동하면 이 순간에 나는 GraphQL에서 오류가 있습니다

Error: User.photo field type must be Output Type but got: undefined. 
    at invariant (/Users/Vadim/Dropbox/WebStormProjects/mulibwanji/node_modules/graphql/jsutils/invariant.js:19:11) 
    at /Users/Vadim/Dropbox/WebStormProjects/mulibwanji/node_modules/graphql/type/definition.js:335:5 
    at Array.forEach (native) 
    at defineFieldMap (/Users/Vadim/Dropbox/WebStormProjects/mulibwanji/node_modules/graphql/type/definition.js:326:14) 
    at GraphQLObjectType.getFields (/Users/Vadim/Dropbox/WebStormProjects/mulibwanji/node_modules/graphql/type/definition.js:284:44) 
    at typeMapReducer (/Users/Vadim/Dropbox/WebStormProjects/mulibwanji/node_modules/graphql/type/schema.js:206:25) 
    at typeMapReducer (/Users/Vadim/Dropbox/WebStormProjects/mulibwanji/node_modules/graphql/type/schema.js:187:12) 
    at /Users/Vadim/Dropbox/WebStormProjects/mulibwanji/node_modules/graphql/type/schema.js:216:20 
    at Array.forEach (native) 
    at typeMapReducer (/Users/Vadim/Dropbox/WebStormProjects/mulibwanji/node_modules/graphql/type/schema.js:207:27) 
    at Array.reduce (native) 
    at new GraphQLSchema (/Users/Vadim/Dropbox/WebStormProjects/mulibwanji/node_modules/graphql/type/schema.js:95:34) 
    at Object.<anonymous> (/Users/Vadim/Dropbox/WebStormProjects/mulibwanji/graphql/Schema.js:58:16) 

답변

0

이 순간 나는이와 바이 패스 :

export const File = new GraphQLObjectType({ 
    name: 'KeystoneFileType', 
    fields: { 
    size: { type: GraphQLInt }, 
    filename: { type: GraphQLString }, 
    mimetype: { type: GraphQLString }, 
    }, 
}); 

그래서 내가 볼로 (필드) =>에 FileType없이 이동에 반드시이 시간에 ,하지만 누군가 진짜 문제를 발견하게되면 기뻐할 것입니다.

관련 문제