2016-09-14 4 views
1

내가 graphql에 명시 서버를 실행하기 위해 노력하고있어 나는 다음과 같은 오류 얻을 :GraphQL : Query.example 필드 유형 출력 유형 만 가지고해야합니다 : [개체 개체]

Error: Query.example field type must be Output Type but got: [object Object].

익스프레스를

app.use('/graphql', graphqlHTTP(req => ({ 
schema, 
pretty: true 
}))); 

스키마가 다음과 같습니다 : 경로에 사용 graphql

export default new GraphQLSchema({ 
query: new GraphQLObjectType({ 
    name: 'Query', 
    fields: queries 
}) 
}); 

쿼리는 하나 개의 쿼리를 가지 여기에서 수입 :

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

import exampleScheme from '../models/schemes/example'; 
import {example as exampleData} from '../models/jsons' 

export default { 
type: exampleScheme, 
resolve (root, params, options) { 
    return exampleData; 
} 
}; 

스키마 (exampleScheme) 및 데이터 (exampleScheme가) 다른 프로젝트에 노력하고 있습니다 그래서 나는 그들이 문제가 아니에요 가정합니다.

아이디어가 있으십니까? '출력 유형'의 의미는 무엇입니까?

export default { 
helloString: { 
    type: GraphQLString, 
    resolve (root, params, options) { 
     return "Hello World!"; 
    } 
} 
... <Next query> 
}; 

어쨌든, 오류는 다음과 같습니다

export default { 
type: exampleScheme, 
resolve (root, params, options) { 
    return exampleData; 
} 
}; 

이 쿼리입니다

답변

2

경우에, 당신은 잘못, 쿼리의 필드, 당신의 예에 따라서 쿼리는 다음과 같이보고해야 얻었다 'type'은 유효한 GraphQLType이 아닙니다.

을 : 의미가 exampleScheme가 다른 객체, 당신이 사용하여 작성하시기 바랍니다임을 있다면

{ 
    testString: "Hello World!" 
} 

: 다음 쿼리가 발생합니다이

query { 
    testString 
} 

모양을

new GraphQLObjectType({ .... Options }); 

희망 하시겠습니까? :)

+0

감사합니다 HagaiCo, 내가 다른 프로젝트에서 스키마를 가져 왔기 때문에, 'GraphQLObjectType'대신 'GraphQLSchema'스키마가 사용되었습니다. – alonp99