Skip to content

Commit

Permalink
Merge branch 'main' into process-client-pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrykWalach committed Nov 10, 2024
2 parents 8a113c8 + 58e38cf commit 941d72a
Show file tree
Hide file tree
Showing 87 changed files with 1,444 additions and 776 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/build-cli.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
on:
workflow_call:
inputs:
target:
required: true
type: string
os:
required: true
type: string
build-name:
required: true
type: string
artifact-name:
required: true
type: string
longpaths:
required: false
type: boolean
cross:
required: false
type: boolean

jobs:
build-cli:
name: Build compiler
timeout-minutes: 10
runs-on: ${{ inputs.os }}
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.75.0
override: true
target: ${{ inputs.target }}
# more info here:- https://github.com/rust-lang/cargo/issues/13020
- name: Enable longer pathnames for git
if: inputs.longpaths
run: git config --system core.longpaths true
- name: Install cross
if: inputs.cross
uses: actions-rs/cargo@v1
with:
command: install
args: cross
- name: 'Build isograph_cli with cargo (${{inputs.target}})'
run: ${{ inputs.cross && 'cross' || 'cargo' }} build --target ${{ inputs.target }} --release
- uses: actions/upload-artifact@v4
with:
name: ${{ inputs.artifact-name }}
path: target/${{ inputs.target }}/release/${{ inputs.build-name }}
if-no-files-found: error
60 changes: 24 additions & 36 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@ permissions:
jobs:
build-cli:
name: Build compiler
timeout-minutes: 10
strategy:
matrix:
target:
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
build-name: isograph_cli
artifact-name: isograph_cli-linux-x64
- target: aarch64-unknown-linux-musl
os: ubuntu-latest
build-name: isograph_cli
Expand All @@ -36,36 +31,28 @@ jobs:
longpaths: true
build-name: isograph_cli.exe
artifact-name: isograph_cli-bin-win-x64
runs-on: ${{ matrix.target.os }}
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.75.0
override: true
target: ${{ matrix.target.target }}
# more info here:- https://github.com/rust-lang/cargo/issues/13020
- name: Enable longer pathnames for git
if: matrix.target.longpaths
run: git config --system core.longpaths true
- name: Install cross
if: matrix.target.cross
uses: actions-rs/cargo@v1
with:
command: install
args: cross
- name: 'Build isograph_cli with cargo (${{matrix.target.target}})'
run: ${{ matrix.target.cross && 'cross' || 'cargo' }} build --target ${{ matrix.target.target }} --release
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.target.artifact-name }}
path: target/${{ matrix.target.target }}/release/${{ matrix.target.build-name }}
if-no-files-found: error
uses: ./.github/workflows/build-cli.yml
with:
target: ${{ matrix.target.target }}
os: ${{ matrix.target.os }}
build-name: ${{ matrix.target.build-name }}
artifact-name: ${{ matrix.target.artifact-name }}
longpaths: ${{ matrix.target.longpaths || false }}
cross: ${{ matrix.target.cross || false }}

build-cli-linux:
name: Build compiler (x86_64-unknown-linux-musl)
uses: ./.github/workflows/build-cli.yml
with:
target: x86_64-unknown-linux-musl
os: ubuntu-latest
build-name: isograph_cli
artifact-name: isograph_cli-linux-x64

build-demos:
name: Build demos
runs-on: ubuntu-latest
needs: [build-cli]
needs: [build-cli-linux]
strategy:
matrix:
target:
Expand Down Expand Up @@ -103,7 +90,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: pnpm/action-setup@v2
- name: Use Node.js 18
- name: Use Node.js 22
uses: actions/setup-node@v3
with:
node-version: 22
Expand All @@ -124,7 +111,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: pnpm/action-setup@v2
- name: Use Node.js 18
- name: Use Node.js 22
uses: actions/setup-node@v3
with:
node-version: 22
Expand All @@ -150,7 +137,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
- name: Use Node.js 18
- name: Use Node.js 22
uses: actions/setup-node@v3
with:
node-version: 22
Expand All @@ -176,7 +163,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
- name: Use Node.js 18
- name: Use Node.js 22
uses: actions/setup-node@v3
with:
node-version: 22
Expand Down Expand Up @@ -227,6 +214,7 @@ jobs:
[
build-js-packages,
build-cli,
build-cli-linux,
build-demos,
build-website,
prettier,
Expand All @@ -249,7 +237,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
- name: Use Node.js 18
- name: Use Node.js 22
uses: actions/setup-node@v3
with:
node-version: 22
Expand Down
2 changes: 0 additions & 2 deletions crates/common_lang_types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ mod path_and_content;
mod span;
mod string_key_types;
mod text_with_carats;
mod traits;

pub use location::*;
pub use path_and_content::*;
pub use span::*;
pub use string_key_types::*;
pub use traits::*;
4 changes: 0 additions & 4 deletions crates/common_lang_types/src/traits.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use intern::Lookup;

use isograph_config::GenerateFileExtensionsOption;
use isograph_schema::{
RefetchedPathsMap, SchemaServerFieldInlineFragmentVariant, UserWrittenClientFieldInfo,
RefetchedPathsMap, ServerFieldTypeAssociatedDataInlineFragment, UserWrittenClientFieldInfo,
UserWrittenComponentVariant, ValidatedClientField, ValidatedSchema, ValidatedSchemaServerField,
};
use std::{
Expand Down Expand Up @@ -133,7 +133,7 @@ pub(crate) fn generate_eager_reader_artifacts(
pub(crate) fn generate_eager_reader_condition_artifact(
schema: &ValidatedSchema,
encountered_server_field: &ValidatedSchemaServerField,
inline_fragment: &SchemaServerFieldInlineFragmentVariant,
inline_fragment: &ServerFieldTypeAssociatedDataInlineFragment,
refetch_paths: &RefetchedPathsMap,
file_extensions: GenerateFileExtensionsOption,
) -> ArtifactPathAndContent {
Expand Down
55 changes: 42 additions & 13 deletions crates/graphql_artifact_generation/src/entrypoint_artifact.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use std::collections::BTreeSet;

use common_lang_types::{ArtifactPathAndContent, QueryOperationName, VariableName};
use common_lang_types::{
ArtifactPathAndContent, IsographObjectTypeName, QueryOperationName, VariableName,
};
use intern::{string_key::Intern, Lookup};
use isograph_config::GenerateFileExtensionsOption;
use isograph_lang_types::{ClientFieldId, IsographSelectionVariant};
use isograph_lang_types::{ClientFieldId, IsographSelectionVariant, ServerObjectId};
use isograph_schema::{
create_merged_selection_map_for_field_and_insert_into_global_map,
current_target_merged_selections, get_imperatively_loaded_artifact_info,
Expand All @@ -30,6 +32,7 @@ struct EntrypointArtifactInfo<'schema> {
query_text: QueryText,
normalization_ast_text: NormalizationAstText,
refetch_query_artifact_import: RefetchQueryArtifactImport,
concrete_type: IsographObjectTypeName,
}

pub(crate) fn generate_entrypoint_artifacts(
Expand Down Expand Up @@ -63,19 +66,20 @@ pub(crate) fn generate_entrypoint_artifacts(
.variable_definitions
.iter()
.map(|variable_definition| &variable_definition.item),
&schema.mutation_root_operation_name(),
&schema.find_mutation(),
file_extensions,
)
}

#[allow(clippy::too_many_arguments)]
pub(crate) fn generate_entrypoint_artifacts_with_client_field_traversal_result<'a>(
schema: &ValidatedSchema,
entrypoint: &ValidatedClientField,
merged_selection_map: &MergedSelectionMap,
traversal_state: &ScalarClientFieldTraversalState,
encountered_client_field_map: &ClientFieldToCompletedMergeTraversalStateMap,
variable_definitions: impl Iterator<Item = &'a ValidatedVariableDefinition> + 'a,
default_root_operation_name: &Option<&RootOperationName>,
default_root_operation: &Option<(&ServerObjectId, &RootOperationName)>,
file_extensions: GenerateFileExtensionsOption,
) -> Vec<ArtifactPathAndContent> {
let query_name = entrypoint.name.into();
Expand All @@ -87,14 +91,16 @@ pub(crate) fn generate_entrypoint_artifacts_with_client_field_traversal_result<'
.fetchable_types
.get(&entrypoint.parent_object_id)
.unwrap_or_else(|| {
default_root_operation_name.unwrap_or_else(|| {
schema
.fetchable_types
.iter()
.next()
.expect("Expected at least one fetchable type to exist")
.1
})
default_root_operation
.map(|(_, operation_name)| operation_name)
.unwrap_or_else(|| {
schema
.fetchable_types
.iter()
.next()
.expect("Expected at least one fetchable type to exist")
.1
})
});

let parent_object = schema.server_field_data.object(entrypoint.parent_object_id);
Expand Down Expand Up @@ -143,12 +149,33 @@ pub(crate) fn generate_entrypoint_artifacts_with_client_field_traversal_result<'
let normalization_ast_text =
generate_normalization_ast_text(schema, merged_selection_map.values(), 0);

let concrete_type = schema.server_field_data.object(
if schema
.fetchable_types
.contains_key(&entrypoint.parent_object_id)
{
entrypoint.parent_object_id
} else {
*default_root_operation
.map(|(operation_id, _)| operation_id)
.unwrap_or_else(|| {
schema
.fetchable_types
.iter()
.next()
.expect("Expected at least one fetchable type to exist")
.0
})
},
);

let mut paths_and_contents = vec![EntrypointArtifactInfo {
query_text,
query_name,
parent_type: parent_object,
normalization_ast_text,
refetch_query_artifact_import,
concrete_type: concrete_type.name,
}
.path_and_content(file_extensions)];

Expand Down Expand Up @@ -249,6 +276,7 @@ impl<'schema> EntrypointArtifactInfo<'schema> {
refetch_query_artifact_import,
query_name,
parent_type,
concrete_type,
} = self;
let ts_file_extension = file_extensions.ts();
let entrypoint_params_typename = format!("{}__{}__param", parent_type.name, query_name);
Expand Down Expand Up @@ -277,14 +305,15 @@ impl<'schema> EntrypointArtifactInfo<'schema> {
{} queryText,\n\
{} normalizationAst,\n\
{}}},\n\
{}concreteType: \"{concrete_type}\",\n\
{}readerWithRefetchQueries: {{\n\
{} kind: \"ReaderWithRefetchQueries\",\n\
{} nestedRefetchQueries,\n\
{} readerArtifact: readerResolver,\n\
{}}},\n\
}};\n\n\
export default artifact;\n",
" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "
" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ",
)
}
}
Expand Down
16 changes: 12 additions & 4 deletions crates/graphql_artifact_generation/src/format_parameter_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use common_lang_types::SelectableFieldName;
use graphql_lang_types::{GraphQLNonNullTypeAnnotation, GraphQLTypeAnnotation};

use isograph_lang_types::{
ClientFieldId, ClientPointerId, SelectableServerFieldId, ServerFieldId, TypeAnnotation,
UnionVariant,
ClientFieldId, ClientPointerId, SelectableServerFieldId, SelectionType, ServerFieldId,
TypeAnnotation, UnionVariant,
};
use isograph_schema::{ClientType, FieldType, ValidatedSchema};

Expand Down Expand Up @@ -80,12 +80,20 @@ fn format_field_definition(
) -> String {
match type_ {
FieldType::ServerField(server_field_id) => {
let type_annotation = &schema.server_field(*server_field_id).associated_data;
let type_annotation = match &schema.server_field(*server_field_id).associated_data {
SelectionType::Object(associated_data) => associated_data
.type_name
.clone()
.map(&mut SelectionType::Object),
SelectionType::Scalar(type_name) => {
type_name.clone().map(&mut SelectionType::Scalar)
}
};
format!(
"{}readonly {}: {},\n",
" ".repeat(indentation_level as usize),
name,
format_type_annotation(schema, type_annotation, indentation_level + 1),
format_type_annotation(schema, &type_annotation, indentation_level + 1),
)
}
FieldType::ClientField(_) => {
Expand Down
Loading

0 comments on commit 941d72a

Please sign in to comment.