Relay: [Modern-rc.2] flow generates types inside comments

Created on 21 Apr 2017  路  8Comments  路  Source: facebook/relay

example of generated code:

/**
 * This file was generated by:
 *   relay-compiler
 *
 * @providesModule UserDetail_viewer.graphql
 * @generated SignedSource<<ecde47534f94f95091bee4c0703ce03e>>
 * @flow
 * @nogrep
 */

'use strict';

/*::
import type {ConcreteFragment} from 'relay-runtime';
export type UserDetail_viewer = {
  user?: ?UserDetail_viewer_user;
};

export type UserDetail_viewer_user = {
  id: string;
  name?: ?string;
  email?: ?string;
};
*/

/* eslint-disable comma-dangle, quotes */

const fragment /*: ConcreteFragment*/ = {
  "argumentDefinitions": [
    {
      "kind": "RootArgument",
      "name": "id",
      "type": "ID!"
    }
  ],
  "kind": "Fragment",
  "metadata": null,
  "name": "UserDetail_viewer",
  "selections": [
    {
      "kind": "LinkedField",
      "alias": null,
      "args": [
        {
          "kind": "Variable",
          "name": "id",
          "variableName": "id",
          "type": "ID!"
        }
      ],
      "concreteType": "User",
      "name": "user",
      "plural": false,
      "selections": [
        {
          "kind": "ScalarField",
          "alias": null,
          "args": null,
          "name": "id",
          "storageKey": null
        },
        {
          "kind": "ScalarField",
          "alias": null,
          "args": null,
          "name": "name",
          "storageKey": null
        },
        {
          "kind": "ScalarField",
          "alias": null,
          "args": null,
          "name": "email",
          "storageKey": null
        }
      ],
      "storageKey": null
    }
  ],
  "type": "Viewer"
};

module.exports = fragment;

Most helpful comment

@ekosz is exactly right: this was actually a change to the compiler we made right as we were releasing the rc: it's very easy to support flow-specific files (and flow-outside-comments) within FB, so this wasn't an issue we encountered internally. But if we didn't generate flow types as comments, we'd be forcing others to have some sort of transform or transpiler to strip them, which would be one more reason not to try RelayModern out (or one more step to get hung up on while you're trying it out).

All 8 comments

@sibelius I believe this is on purpose and flow should be able to parse this file just fine.https://flow.org/blog/2015/02/20/Flow-Comments/

As the for the reason this was chosen I'm less clear on.

I'd assume it's so that people who aren't using a transpiler which strips out flow types can still use Relay.

Hm, makes sense

I'll open an issue on Webstorm about it, tks

@ekosz is exactly right: this was actually a change to the compiler we made right as we were releasing the rc: it's very easy to support flow-specific files (and flow-outside-comments) within FB, so this wasn't an issue we encountered internally. But if we didn't generate flow types as comments, we'd be forcing others to have some sort of transform or transpiler to strip them, which would be one more reason not to try RelayModern out (or one more step to get hung up on while you're trying it out).

@mjmahone can we add this as an option to relay-compiler? to generate as comments or to generate as javascript flow code?

@sibelius: Open to have this as a config flag to pass in, but curious what the reason is? The types should be usable without configuration if you use flow.

nevermind, this is a problem with webstorm flow support: https://youtrack.jetbrains.com/issue/WEB-16606

@sibelius maybe an option isn't a bad idea anyway. This could help not only use bare flow to check but also improve chances to integrate it into IDEs, which lack proper support for comment types.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bondanherumurti picture bondanherumurti  路  3Comments

fedbalves picture fedbalves  路  3Comments

johntran picture johntran  路  3Comments

MartinDawson picture MartinDawson  路  3Comments

mike-marcacci picture mike-marcacci  路  3Comments