2016-09-06 3 views
45

향상시킬 구성 요소를 Relay.createContainer으로 (flowtype을 사용하여) 입력하려고합니다.내 보낸 RelayContainer를 입력하는 방법

"react-relay"패키지로 types exported을 들었지만 ReactContainer은 소품을 휴대하지 않는 것 같습니다. - 이제

// Bar.js 
// @flow 

import React from "react"; 
import Foo from "./Foo.js"; 
const Bar =() => <Foo />; 

불평 흐름

// Foo.js 
// @flow 
import React from "react"; 
import Relay from "react-relay"; 

type Props = { title: string; } 
const Foo({ title }: Props) => (<div>{title}</div>); 

const exported: Class<React$Component<void, Props, void>> = Relay.createContainer(Foo, { 
    fragments: { ... } 
}); 

export default exported; 

:

는 내가 얻을 수있는 예상 된 결과에 가장 가까운 것은이 결국 RelayContainer, ReactClass, React$Component 등 실험 Foo.js에서 Bar는 제목 소품을 제공하지 않습니다. 소품은 Bar.js에 신고하고 싶습니다.하지만 세부 사항입니다. 이 이상 수행 그래서 내가 Relay.createContainer의 출력을 입력하기 위해 노력하고있어 결국

// Bar.js 
// @flow 

import React from "react"; 
import Relay from "react-relay"; 
import Foo from "./Foo.js"; 

const Bar =() => <Foo />; 

export default Relay.createContainer(Bar, { 
    fragments: { 
    baz:() => Relay.QL` 
     fragment on Baz { 
     ${Foo.getFragment("foo")} 
     } 
    ` 
    } 
} 

: 바는 또한 푸의 속성에 getFragment을 찾을 수 없다는 불평 것 푸의 조각 흐름을 참조하는 RelayContainer이었다 그러나 경우 데코 레이팅 된 구성 요소의 타이핑 Relay의 내부 유형을 살펴본 후 https://github.com/facebook/relay/blob/8567b2732d94d75f0eacdce4cc43c3606960a1d9/src/query/RelayFragmentReference.js#L211을 보았지만 Relay의 속성을 추가하는 방법이 아닌 것 같습니다.

어떻게하면 좋을까요?

+2

https://github.com/ :

생성은

당신은 다음과 같이 필드 소품의 흐름 유형을 가져올 것이다 릴레이 컴파일러

relay-compiler --src ./src --schema ./schema.json

을 실행하여 파일을 말했다 facebook/relay/pull/1155 – gre

+0

위의 개요가 유망 해 보입니다. Flow에 고차원 컴포넌트가 정적 getFragment 메소드를 추가한다고 말할 수 있도록 추가 할 수 있는지 살펴볼 것입니다. 누구든지 더 나은 대안을 찾은 경우 배우는 것이 좋습니다. – John

+1

Lee Byron은 어제 react-europe에서 Relay 1.0.0이 각 조각에 대해 __generated __/* 파일을 생성하고 flowtype을 내보낼 것이라고 발표했습니다. 그래서 이것으로 해결할 수 있을까요? – gre

답변

2

으로 표시된대로 Relay Compiler는 조각에 대한 Flow 유형을 생성하고이 파일은 __generated__ 하위 디렉토리 내의 생성 된 파일로 내보내집니다.

관련
import type { MyComponent_myField } from "./__generated__/MyComponent_myField.graphql"; 
class MyComponent extends Component<{ 
    myField: MyComponent_myField, 
}> { 
    render() { 
    return <div>Example</div>; 
    } 
} 
export default createFragmentContainer(MyComponent, { 
    myField: graphql` 
    fragment MyComponent_myField on MyType { 
     edges { 
      node { 
      _id 
      foo 
      } 
     } 
    } 
    ` 
});