How to type an exported RelayContainer

as @gre pointed out, now the Relay Compiler generates Flow types for the fragment and these are exported in generated files within a __generated__ subdirectory.

generating said file by running the Relay Compiler

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

You would then import the flow types for the field props like so:

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
          }
       }
    }
  `
});

Although AFAIK currently types for spreaded fragments are not generated unless you use the Haste module system

Leave a Comment