github graphql v4 api의 응답 데이터를 내 구성 요소에 제공하기로되어있는 apollo-wrapped 구성 요소가 있습니다. 내 gql 쿼리에 사용되는 응용 프로그램의 다른 부분에서 문자열 (SEARCH_QUERY)를 사용하려고하지만 github는 undefined
을 반환 유지합니다. 나는 공식 아폴로 문서 http://dev.apollodata.com/react/queries.html#graphql-options을 따르고 있습니다. 내가 잘못하고있는 것을 보지 못한다. 어떻게 react-apollo graphql 쿼리에서 동적 변수를 올바르게 사용할 수 있습니까?
import React, { Component } from 'react';
import { Text, FlatList } from 'react-native';
import { graphql } from 'react-apollo';
import gql from 'graphql-tag';
import { SEARCH_QUERY } from './Home' // this is a string like "react"
// The data prop, which is provided by the wrapper below contains,
// a `loading` key while the query is in flight and posts when ready
const ReposList = ({ data: { loading, search }}) => <Text>SearchResults</Text>
// this doesnt work because I cant properly inject 'SEARCH_QUERY' string
const searchRepos = gql`
query searchRepos($type: searchType!, $query: String!) {
search(type: REPOSITORY, query: $query, first: 100) {
edges {
node {
... on Repository {
nameWithOwner
owner {
login
}
}
}
}
}
}
`
// The `graphql` wrapper executes a GraphQL query and makes the results
// available on the `data` prop of the wrapped component (ReposList here)
export default graphql(searchRepos, {
options: { variables: { query: SEARCH_QUERY }, notifyOnNetworkStatusChange: true }
}
)(ReposList);
변수없이이 쿼리는 잘 작동하고 예상대로 반환 검색 결과를
. 똑바로, 그렇지? 이 github에 사용되는const searchRepos = gql`{
search(type: REPOSITORY, query: "react", first: 100) {
edges {
node {
... on Repository {
nameWithOwner
owner {
login
}
}
}
}
}
} `
는 undefined를 반환합니다. 하지만 실제로 쿼리 내에서 사용하지 마십시오 - 당신이 $type
변수를 정의했기 때문에
const searchRepos = gql`
query searchRepos($type: searchType!, $query: String!) {
search(type: REPOSITORY, query: $query, first: 100) {
edges {
node {
... on Repository {
nameWithOwner
owner {
login
}
}
}
}
}
}
`
그래, 'const를 searchRepos = GQL ($ 쿼리 :! 문자열) { 검색 (유형 : 저장소 쿼리 : 첫번째 $ 쿼리 : 100) { 가장자리 { 노드 { ...이 저장소 { nameWithOwner 소유자 { 로그인 } } } } }에 } ' 는 – fatahn
근무했고과 같이 깔끔하게 소품을 통과했다 '수출 기본 graphql (searchRepos, { 옵션 : ({SEARCHQUERY}) => ({변수 : {쿼리 SEARCHQUERY}}), // notifyOnNetworkStatusChange 소품에서 연산 쿼리 변수 : 사실 }) (ReposList)' ... 감사합니다 @ 다니엘 - rearden – fatahn