Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip importing export types in TS #4754

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ pub fn generate_updatable_query(
// -- Begin Types Section --
let mut section = GenericSection::default();
let generated_types =
ArtifactGeneratedTypes::from_updatable_query(typegen_operation, skip_types);
ArtifactGeneratedTypes::from_updatable_query(typegen_operation, skip_types, project_config.typegen_config.language);

if project_config.typegen_config.language == TypegenLanguage::Flow {
writeln!(section, "/*::")?;
Expand Down Expand Up @@ -358,6 +358,7 @@ pub fn generate_operation(
typegen_operation,
skip_types,
request_parameters.is_client_request(),
project_config.typegen_config.language
);

if project_config.typegen_config.language == TypegenLanguage::Flow {
Expand Down Expand Up @@ -687,7 +688,7 @@ fn generate_read_only_fragment(

// -- Begin Types Section --
let mut section = GenericSection::default();
let generated_types = ArtifactGeneratedTypes::from_fragment(typegen_fragment, skip_types);
let generated_types = ArtifactGeneratedTypes::from_fragment(typegen_fragment, skip_types, project_config.typegen_config.language);

if project_config.typegen_config.language == TypegenLanguage::Flow {
writeln!(section, "/*::")?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ use common::NamedItem;
use graphql_ir::FragmentDefinition;
use graphql_ir::OperationDefinition;
use graphql_syntax::OperationKind;
use relay_config::TypegenLanguage;
use relay_transforms::RefetchableMetadata;
use relay_transforms::INLINE_DIRECTIVE_NAME;
use relay_transforms::UPDATABLE_DIRECTIVE;
use relay_typegen::has_raw_response_type_directive;


/// Specifies the imported and exported generated types of an
/// artifact.
pub struct ArtifactGeneratedTypes {
Expand All @@ -27,8 +29,9 @@ impl ArtifactGeneratedTypes {
operation: &OperationDefinition,
skip_types: bool,
is_client_only: bool,
language: TypegenLanguage,
) -> Self {
if skip_types {
if skip_types || language == TypegenLanguage::TypeScript {
Self {
imported_types: "ConcreteRequest",
ast_type: "ConcreteRequest",
Expand Down Expand Up @@ -80,8 +83,8 @@ impl ArtifactGeneratedTypes {
}
}

pub fn from_updatable_query(typegen_operation: &OperationDefinition, skip_types: bool) -> Self {
if skip_types {
pub fn from_updatable_query(typegen_operation: &OperationDefinition, skip_types: bool, language: TypegenLanguage) -> Self {
if skip_types || language == TypegenLanguage::TypeScript {
Self {
imported_types: "ConcreteUpdatableQuery",
ast_type: "ConcreteUpdatableQuery",
Expand All @@ -100,11 +103,11 @@ impl ArtifactGeneratedTypes {
}
}

pub fn from_fragment(fragment: &FragmentDefinition, skip_types: bool) -> Self {
pub fn from_fragment(fragment: &FragmentDefinition, skip_types: bool, language: TypegenLanguage) -> Self {
let is_inline_data_fragment = fragment.directives.named(*INLINE_DIRECTIVE_NAME).is_some();
let is_updatable_fragment = fragment.directives.named(*UPDATABLE_DIRECTIVE).is_some();

if skip_types {
if skip_types || language == TypegenLanguage::TypeScript {
if is_inline_data_fragment {
Self {
imported_types: "ReaderInlineDataFragment",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type Post {
==================================== OUTPUT ===================================
//- __generated__/foo.graphql.ts
/**
* <auto-generated> SignedSource<<0e503f5c200310a5580a2b4853a499ce>>
* <auto-generated> SignedSource<<fbfb0da0e84763fffee1d191d9a7f6c4>>
* @lightSyntaxTransform
* @nogrep
*/
Expand All @@ -48,7 +48,7 @@ type Post {
/* eslint-disable */
// @ts-nocheck

import { Fragment, ReaderFragment } from 'relay-runtime';
import { ReaderFragment } from 'relay-runtime';
import { FragmentRefs } from "relay-runtime";
export type foo$data = {
readonly posts: ReadonlyArray<{
Expand Down Expand Up @@ -108,7 +108,7 @@ export default node;

//- __generated__/fooQuery.graphql.ts
/**
* <auto-generated> SignedSource<<20043d1d00f946a33727d27907f7f3f2>>
* <auto-generated> SignedSource<<119739ea84b9bdf74d937309d38abba4>>
* @lightSyntaxTransform
* @nogrep
*/
Expand All @@ -117,7 +117,7 @@ export default node;
/* eslint-disable */
// @ts-nocheck

import { ConcreteRequest, Query } from 'relay-runtime';
import { ConcreteRequest } from 'relay-runtime';
import { FragmentRefs } from "relay-runtime";
export type fooQuery$variables = Record<PropertyKey, never>;
export type fooQuery$data = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default node;

//- __generated__/fooQuery.graphql.ts
/**
* <auto-generated> SignedSource<<461989c03655ebfecf253b741f65ef91>>
* <auto-generated> SignedSource<<fb8fb1474f3e44f8818e0d2fb6490eae>>
* @relayHash ae6874c86ce5db2df8d6b253a6a0ec13
* @lightSyntaxTransform
* @nogrep
Expand All @@ -65,7 +65,7 @@ export default node;

// @relayRequestID ae6874c86ce5db2df8d6b253a6a0ec13

import { ConcreteRequest, Query } from 'relay-runtime';
import { ConcreteRequest } from 'relay-runtime';
export type fooQuery$variables = Record<PropertyKey, never>;
export type fooQuery$data = {
readonly userName: string | null | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type User { name: String }
==================================== OUTPUT ===================================
//- __generated__/foo.graphql.ts
/**
* <auto-generated> SignedSource<<b8a79927acf6eb285be2d05e7d209ab8>>
* <auto-generated> SignedSource<<d2b6a2fbf057fd52d8aa0869bcccbe8e>>
* @lightSyntaxTransform
* @nogrep
*/
Expand All @@ -26,7 +26,7 @@ type User { name: String }
/* eslint-disable */
// @ts-nocheck

import { Fragment, ReaderFragment } from 'relay-runtime';
import { ReaderFragment } from 'relay-runtime';
import { FragmentRefs } from "relay-runtime";
export type foo$data = {
readonly name: string | null | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type User { name: String }
==================================== OUTPUT ===================================
//- __generated__/barFragment.graphql.ts
/**
* <auto-generated> SignedSource<<6c58dff465555ee63fe212edde3a3e01>>
* <auto-generated> SignedSource<<f592d795251b0c88f6e5456bd47a8d10>>
* @lightSyntaxTransform
* @nogrep
*/
Expand All @@ -34,7 +34,7 @@ type User { name: String }
/* eslint-disable */
// @ts-nocheck

import { Fragment, ReaderFragment } from 'relay-runtime';
import { ReaderFragment } from 'relay-runtime';
import { FragmentRefs } from "relay-runtime";
import { foo as userFooResolverType } from "../foo";
export type barFragment$data = {
Expand Down