2016-08-22 4 views
0

graphql을 사용하여 좌표 배열을 가져 오려고합니다. 내가 얻을 수 graphiql를 사용Graphql 쿼리 배열

type Country implements Node { 
    code: String 
    name: String 
    dictionary: [CountryDictionary] 
    language: [CountryLanguage] 
    loc: [CountryLoc] 
    creationDate: Date 
    modifiedDate: Date 
    _id: ID 
    id: ID! 
} 

type CountryConnection { 
    pageInfo: PageInfo! 
    edges: [CountryEdge] 
    count: Float 
} 

type CountryDictionary { 
    _id: Generic 
    value: String 
} 

input CountryDictionaryInput { 
    _id: Generic 
    value: String 
} 

type CountryEdge { 
    node: Country 
    cursor: String! 
} 

type CountryLanguage { 
    _id: Generic 
    code: String 
    name: String 
} 

input CountryLanguageInput { 
    _id: Generic 
    code: String 
    name: String 
} 

type CountryLoc { 
    type: String 
    coordinates: [Float] 
} 

input CountryLocInput { 
    type: String 
    coordinates: [Float] 
} 

: 여기

// Geometry 
const GeometrySchema = new mongoose.Schema({ 
type:   { type: String }, 
coordinates: [ Number ] 
}, { _id: false }); 

// Country 
const CountrySchema = new mongoose.Schema({ 
code:   String, 
name:   String, 
dictionary:  [ { _id: false, value: String } ], 
language:  [ { _id: false, code: String, name: String } ], 
loc:   { type: { type: String }, geometries: [ GeometrySchema ] }, 
creationDate: Date, 
modifiedDate: Date 
}); 

const Country = mongoose.model('Country', CountrySchema); 

생성 graphql (graphql/유틸리티) 것 : 나는이 몽구스 모델에서 graphql 유형을 생성하는 릴레이, 몽구스, 낙서 - 몽구스를 사용하고 있습니다 그 나라의 이름은 다음과 같습니다 :

{ 
    country(id:"57b48b73f6d183802aa06fe8"){ 
    name 

    } 
} 

loc 정보를 어떻게 검색 할 수 있습니까?

+0

당신이'밖으로 시도해 봤어 :' { 국가 (ID "57b48b73f6d183802aa06fe8을") { 이름 LOC는 { 는 } } 을 조정}? –

+0

예이 응답을 얻으려고합니다. { "statusCode": 400, "오류": "잘못된 요청", "메시지": "예상되는 반복 가능하지만 Country.loc 필드에 하나가 없습니다." } – ric

+0

즉, 문제는 서버 측 구현과 관련이 있습니다. 서버 측에서 좌표의 배열을 제대로 반환했는지 확인하십시오. –

답변

0

이 스키마에 따르면, 쿼리는 것 그것은 스키마 생성의 가능성 벌레처럼 보이는이

{ 
    country(id:"57b48b73f6d183802aa06fe8") { 
    name 
    loc { 
     type 
     coordinates 
    } 
    } 
} 
+0

안녕하세요. 답변 해 주셔서 감사합니다. 이 쿼리 결과는 다음과 같습니다. { "statusCode": 400, "오류": "잘못된 요청", "메시지": "예상되는 반복 가능하지만 Country.loc 필드에서 찾을 수 없습니다." } – ric

+0

당신의 몽구스'CountrySchema'는'loc' 속성이 배열 대신에 단일 객체로 정의됩니다. 그리고 당신의 타입 스키마는'[CountryLoc]'리스트로 정의 된 loc 필드를 가지고 있습니다. 귀하의 모델은 단지 배열을 반환하지 않습니다 – LordDave

+0

네, 맞습니다. mongoose 모델은 괜찮지 만 graphql 유형을 생성하는 데 사용되는 유틸리티 graffiti-mongoose는 하위 문서에 제한이 있습니다. 고맙습니다. – ric