Skip to content

Commit

Permalink
remove existingFragmentNames compat feature
Browse files Browse the repository at this point in the history
Summary:
In compat mode, Relay could reference fragments that didn't actually exist. Those fragments would also not have types defined that could be imported
Since we no longer use compat mode, this removes this flag to reduce the number of options we support.

Reviewed By: alunyov

Differential Revision: D20129609

fbshipit-source-id: f73463e341a2215b840583b033b3acb65bfbfa7f
  • Loading branch information
kassens authored and facebook-github-bot committed Feb 27, 2020
1 parent c2df75e commit a49b208
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 58 deletions.
11 changes: 0 additions & 11 deletions packages/relay-compiler/codegen/RelayFileWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,6 @@ function writeAll({
]),
);

const existingFragmentNames = new Set(
definitions.map(definition => definition.name),
);

const definitionsMeta = new Map();
const getDefinitionMeta = (definitionName: string) => {
const artifact = nullthrows(artifactMap.get(definitionName));
Expand All @@ -219,12 +215,6 @@ function writeAll({
});
});

// TODO(T22651734): improve this to correctly account for fragments that
// have generated flow types.
baseDefinitionNames.forEach(baseDefinitionName => {
existingFragmentNames.delete(baseDefinitionName);
});

const allOutputDirectories: Map<string, CodegenDirectory> = new Map();
const addCodegenDir = dirPath => {
const codegenDir = new CodegenDirectory(dirPath, {
Expand Down Expand Up @@ -289,7 +279,6 @@ function writeAll({
{
customScalars: writerConfig.customScalars,
enumsHasteModule: writerConfig.enumsHasteModule,
existingFragmentNames,
optionalInputFields: writerConfig.optionalInputFieldsForFlow,
useHaste: writerConfig.useHaste,
useSingleArtifactDirectory: !!writerConfig.outputDir,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,6 @@ export type TypeGeneratorOptions = {|
*/
+customScalars: ScalarTypeMapping,

/**
* Lists all other fragments relay-compiler knows about. Use this to know when
* to import/reference other artifacts.
*/
+existingFragmentNames: Set<string>,

/**
* Whether or not relay-compiler will store artifacts next to the module that
* they originate from or all together in a single directory.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ function createVisitor(schema: Schema, options: TypeGeneratorOptions) {
const state = {
customScalars: options.customScalars,
enumsHasteModule: options.enumsHasteModule,
existingFragmentNames: options.existingFragmentNames,
generatedFragments: new Set(),
generatedInputObjectTypes: {},
optionalInputFields: options.optionalInputFields,
Expand Down Expand Up @@ -877,16 +876,13 @@ function getFragmentImports(state: State) {
for (const usedFragment of usedFragments) {
const fragmentTypeName = getOldFragmentTypeName(usedFragment);
if (!state.generatedFragments.has(usedFragment)) {
if (state.useHaste && state.existingFragmentNames.has(usedFragment)) {
if (state.useHaste) {
// TODO(T22653277) support non-haste environments when importing
// fragments
imports.push(
importTypes([fragmentTypeName], usedFragment + '.graphql'),
);
} else if (
state.useSingleArtifactDirectory &&
state.existingFragmentNames.has(usedFragment)
) {
} else if (state.useSingleArtifactDirectory) {
imports.push(
importTypes([fragmentTypeName], './' + usedFragment + '.graphql'),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ describe('Snapshot tests', () => {
text,
{
customScalars: {},
existingFragmentNames: new Set(['PhotoFragment']),
optionalInputFields: [],
useHaste: true,
useSingleArtifactDirectory: false,
Expand All @@ -103,7 +102,6 @@ describe('Snapshot tests', () => {
text,
{
customScalars: {},
existingFragmentNames: new Set(['PhotoFragment']),
optionalInputFields: [],
useHaste: false,
useSingleArtifactDirectory: true,
Expand All @@ -123,7 +121,6 @@ describe('Snapshot tests', () => {
text,
{
customScalars: {},
existingFragmentNames: new Set(['PhotoFragment']),
optionalInputFields: [],
useHaste: false,
useSingleArtifactDirectory: false,
Expand All @@ -144,7 +141,6 @@ it('does not add `%future added values` when the noFutureProofEnums option is se
`;
const types = generate(text, {
customScalars: {},
existingFragmentNames: new Set(['PhotoFragment']),
optionalInputFields: [],
useHaste: true,
useSingleArtifactDirectory: false,
Expand All @@ -166,7 +162,6 @@ test('import enum definitions from single module', () => {
const types = generate(text, {
customScalars: {},
enumsHasteModule: 'MyGraphQLEnums',
existingFragmentNames: new Set([]),
optionalInputFields: [],
useHaste: true,
noFutureProofEnums: false,
Expand All @@ -186,7 +181,6 @@ test('import enum definitions from enum specific module', () => {
const types = generate(text, {
customScalars: {},
enumsHasteModule: (enumName: string) => `${enumName}.graphqlenum`,
existingFragmentNames: new Set([]),
optionalInputFields: [],
useHaste: true,
noFutureProofEnums: false,
Expand All @@ -206,7 +200,6 @@ describe('custom scalars', () => {
`;
const generateWithMapping = mapping =>
generate(text, {
existingFragmentNames: new Set([]),
optionalInputFields: [],
useHaste: false,
customScalars: mapping,
Expand Down Expand Up @@ -253,7 +246,6 @@ it('imports fragment refs from siblings in a single artifact dir', () => {
`;
const types = generate(text, {
customScalars: {},
existingFragmentNames: new Set(['PhotoFragment']),
optionalInputFields: [],
// This is what's different from the tests above.
useHaste: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ fragment UserFrag2 on User {

~~~~~~~~~~ OUTPUT ~~~~~~~~~~
// FragmentSpread.graphql
type OtherFragment$ref = any;
type PictureFragment$ref = any;
type UserFrag1$ref = any;
type UserFrag2$ref = any;
import type { OtherFragment$ref } from "OtherFragment.graphql";
import type { PictureFragment$ref } from "PictureFragment.graphql";
import type { UserFrag1$ref } from "UserFrag1.graphql";
import type { UserFrag2$ref } from "UserFrag2.graphql";
import type { FragmentReference } from "relay-runtime";
declare export opaque type FragmentSpread$ref: FragmentReference;
declare export opaque type FragmentSpread$fragmentType: FragmentSpread$ref;
Expand All @@ -169,7 +169,7 @@ export type FragmentSpread$key = {
};

// ConcreateTypes.graphql
type PageFragment$ref = any;
import type { PageFragment$ref } from "PageFragment.graphql";
import type { FragmentReference } from "relay-runtime";
declare export opaque type ConcreateTypes$ref: FragmentReference;
declare export opaque type ConcreateTypes$fragmentType: ConcreateTypes$ref;
Expand Down Expand Up @@ -417,7 +417,7 @@ export type InlineFragmentConditionalID$key = {
};

// InlineFragmentKitchenSink.graphql
type SomeFragment$ref = any;
import type { SomeFragment$ref } from "SomeFragment.graphql";
import type { FragmentReference } from "relay-runtime";
declare export opaque type InlineFragmentKitchenSink$ref: FragmentReference;
declare export opaque type InlineFragmentKitchenSink$fragmentType: InlineFragmentKitchenSink$ref;
Expand Down Expand Up @@ -566,8 +566,8 @@ fragment MarkdownUserNameRenderer_name on MarkdownUserNameRenderer {

~~~~~~~~~~ OUTPUT ~~~~~~~~~~
// NameRendererFragment.graphql
type MarkdownUserNameRenderer_name$ref = any;
type PlainUserNameRenderer_name$ref = any;
import type { MarkdownUserNameRenderer_name$ref } from "MarkdownUserNameRenderer_name.graphql";
import type { PlainUserNameRenderer_name$ref } from "PlainUserNameRenderer_name.graphql";
import type { FragmentReference } from "relay-runtime";
declare export opaque type NameRendererFragment$ref: FragmentReference;
declare export opaque type NameRendererFragment$fragmentType: NameRendererFragment$ref;
Expand Down Expand Up @@ -652,8 +652,8 @@ fragment MarkdownUserNameRenderer_name on MarkdownUserNameRenderer {

~~~~~~~~~~ OUTPUT ~~~~~~~~~~
// NameRendererQuery.graphql
type MarkdownUserNameRenderer_name$ref = any;
type PlainUserNameRenderer_name$ref = any;
import type { MarkdownUserNameRenderer_name$ref } from "MarkdownUserNameRenderer_name.graphql";
import type { PlainUserNameRenderer_name$ref } from "PlainUserNameRenderer_name.graphql";
export type NameRendererQueryVariables = {||};
export type NameRendererQueryResponse = {|
+me: ?{|
Expand Down Expand Up @@ -793,7 +793,7 @@ fragment InlineFragmentWithOverlappingFields on Actor {

~~~~~~~~~~ OUTPUT ~~~~~~~~~~
// TestMutation.graphql
type InlineFragmentWithOverlappingFields$ref = any;
import type { InlineFragmentWithOverlappingFields$ref } from "InlineFragmentWithOverlappingFields.graphql";
export type CommentCreateInput = {|
clientMutationId?: ?string,
feedbackId?: ?string,
Expand Down Expand Up @@ -999,7 +999,7 @@ fragment FriendFragment on User {

~~~~~~~~~~ OUTPUT ~~~~~~~~~~
// CommentCreateMutation.graphql
type FriendFragment$ref = any;
import type { FriendFragment$ref } from "FriendFragment.graphql";
export type TestEnums = "mark" | "zuck" | "%future added value";
export type CommentCreateInput = {|
clientMutationId?: ?string,
Expand Down Expand Up @@ -1115,7 +1115,7 @@ fragment FeedbackFragment on Feedback {

~~~~~~~~~~ OUTPUT ~~~~~~~~~~
// CommentCreateMutation.graphql
type FriendFragment$ref = any;
import type { FriendFragment$ref } from "FriendFragment.graphql";
export type CommentCreateInput = {|
clientMutationId?: ?string,
feedbackId?: ?string,
Expand Down Expand Up @@ -1173,7 +1173,7 @@ export type CommentCreateMutation = {|
|};

// FriendFragment.graphql
type FeedbackFragment$ref = any;
import type { FeedbackFragment$ref } from "FeedbackFragment.graphql";
import type { FragmentReference } from "relay-runtime";
declare export opaque type FriendFragment$ref: FragmentReference;
declare export opaque type FriendFragment$fragmentType: FriendFragment$ref;
Expand Down Expand Up @@ -1342,7 +1342,7 @@ fragment MarkdownUserNameRenderer_name on MarkdownUserNameRenderer {
~~~~~~~~~~ OUTPUT ~~~~~~~~~~
// Test.graphql
import type { Local3DPayload } from "relay-runtime";
type NameRendererFragment$ref = any;
import type { NameRendererFragment$ref } from "NameRendererFragment.graphql";
export type TestVariables = {||};
export type TestResponse = {|
+node: ?{|
Expand Down Expand Up @@ -1398,8 +1398,8 @@ export type Test = {|
|};

// NameRendererFragment.graphql
type MarkdownUserNameRenderer_name$ref = any;
type PlainUserNameRenderer_name$ref = any;
import type { MarkdownUserNameRenderer_name$ref } from "MarkdownUserNameRenderer_name.graphql";
import type { PlainUserNameRenderer_name$ref } from "PlainUserNameRenderer_name.graphql";
import type { FragmentReference } from "relay-runtime";
declare export opaque type NameRendererFragment$ref: FragmentReference;
declare export opaque type NameRendererFragment$fragmentType: NameRendererFragment$ref;
Expand Down Expand Up @@ -1479,7 +1479,7 @@ fragment Test_userRenderer on PlainUserRenderer {
~~~~~~~~~~ OUTPUT ~~~~~~~~~~
// Test.graphql
import type { Local3DPayload } from "relay-runtime";
type Test_user$ref = any;
import type { Test_user$ref } from "Test_user.graphql";
export type TestVariables = {||};
export type TestResponse = {|
+node: ?{|
Expand Down Expand Up @@ -1514,7 +1514,7 @@ export type Test = {|
|};

// Test_user.graphql
type Test_userRenderer$ref = any;
import type { Test_userRenderer$ref } from "Test_userRenderer.graphql";
import type { FragmentReference } from "relay-runtime";
declare export opaque type Test_user$ref: FragmentReference;
declare export opaque type Test_user$fragmentType: Test_user$ref;
Expand Down Expand Up @@ -1605,8 +1605,8 @@ fragment MarkdownUserNameRenderer_name on MarkdownUserNameRenderer {
~~~~~~~~~~ OUTPUT ~~~~~~~~~~
// Test.graphql
import type { Local3DPayload } from "relay-runtime";
type AnotherNameRendererFragment$ref = any;
type NameRendererFragment$ref = any;
import type { AnotherNameRendererFragment$ref } from "AnotherNameRendererFragment.graphql";
import type { NameRendererFragment$ref } from "NameRendererFragment.graphql";
export type TestVariables = {||};
export type TestResponse = {|
+node: ?{|
Expand Down Expand Up @@ -1699,8 +1699,8 @@ export type Test = {|
|};

// NameRendererFragment.graphql
type MarkdownUserNameRenderer_name$ref = any;
type PlainUserNameRenderer_name$ref = any;
import type { MarkdownUserNameRenderer_name$ref } from "MarkdownUserNameRenderer_name.graphql";
import type { PlainUserNameRenderer_name$ref } from "PlainUserNameRenderer_name.graphql";
import type { FragmentReference } from "relay-runtime";
declare export opaque type NameRendererFragment$ref: FragmentReference;
declare export opaque type NameRendererFragment$fragmentType: NameRendererFragment$ref;
Expand All @@ -1721,8 +1721,8 @@ export type NameRendererFragment$key = {
};

// AnotherNameRendererFragment.graphql
type MarkdownUserNameRenderer_name$ref = any;
type PlainUserNameRenderer_name$ref = any;
import type { MarkdownUserNameRenderer_name$ref } from "MarkdownUserNameRenderer_name.graphql";
import type { PlainUserNameRenderer_name$ref } from "PlainUserNameRenderer_name.graphql";
import type { FragmentReference } from "relay-runtime";
declare export opaque type AnotherNameRendererFragment$ref: FragmentReference;
declare export opaque type AnotherNameRendererFragment$fragmentType: AnotherNameRendererFragment$ref;
Expand Down Expand Up @@ -1800,7 +1800,7 @@ fragment FriendFragment on User {

~~~~~~~~~~ OUTPUT ~~~~~~~~~~
// ExampleQuery.graphql
type FriendFragment$ref = any;
import type { FriendFragment$ref } from "FriendFragment.graphql";
export type ExampleQueryVariables = {|
id: string,
condition: boolean,
Expand Down Expand Up @@ -1879,7 +1879,7 @@ fragment FriendFragment on User {

~~~~~~~~~~ OUTPUT ~~~~~~~~~~
// ExampleQuery.graphql
type FriendFragment$ref = any;
import type { FriendFragment$ref } from "FriendFragment.graphql";
export type ExampleQueryVariables = {|
id: string
|};
Expand Down

0 comments on commit a49b208

Please sign in to comment.