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

Generate schema for isograph.config.json #290

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
5acc0d1
process client pointer
PatrykWalach Nov 6, 2024
f8e539f
fix parse
PatrykWalach Nov 6, 2024
dd5582a
update `encountered_fields`
PatrykWalach Nov 6, 2024
753cd98
refactor `validate_isograph_selection_set_directives`
PatrykWalach Nov 6, 2024
050b5aa
use `ClientType`
PatrykWalach Nov 7, 2024
8a113c8
change error message
PatrykWalach Nov 7, 2024
941d72a
Merge branch 'main' into process-client-pointer
PatrykWalach Nov 10, 2024
fdc36c3
replace `None` with `todo!()`
PatrykWalach Nov 12, 2024
61e70e8
map Span with `and_then`
PatrykWalach Nov 12, 2024
e514dff
rename args to `scalar_field_selection` and `object_pointer_selection`
PatrykWalach Nov 12, 2024
a34cb58
refactor span with `and_then`
PatrykWalach Nov 12, 2024
aec18e5
fix typo `encountered` error message
PatrykWalach Nov 12, 2024
61f02e8
remove `unwraps`
PatrykWalach Nov 12, 2024
4f6bc48
update comments
PatrykWalach Nov 12, 2024
13047c5
completely remove `unwraps`
PatrykWalach Nov 12, 2024
81dafea
use `GraphQLTypeAnnotation` for `to_type`
PatrykWalach Nov 13, 2024
8d9614a
Merge branch 'main' into process-client-pointer
PatrykWalach Nov 13, 2024
a626af2
generate json schema
PatrykWalach Nov 13, 2024
5b0fa7d
use generated schema
PatrykWalach Nov 13, 2024
82aa102
build schema in ci before publish
PatrykWalach Dec 12, 2024
d067a5d
Merge branch 'main' into generate-json-schema
PatrykWalach Dec 21, 2024
779aeb4
generate json schema
PatrykWalach Nov 13, 2024
7f98886
use generated schema
PatrykWalach Nov 13, 2024
1d8627f
build schema in ci before publish
PatrykWalach Dec 12, 2024
4f7a627
chore: Fix vite-demo type checking (#265)
lanesawyer Nov 13, 2024
82f0724
update docs and demo slightly (#275)
rbalicki2 Nov 14, 2024
80793a4
no need to return data in example
rbalicki2 Nov 14, 2024
c661490
update docs some more
rbalicki2 Nov 14, 2024
bacf688
FetchOptions now have optional `onCompleted` and `onError` callbacks.
rbalicki2 Nov 14, 2024
8ff0f08
add more to documentation
rbalicki2 Nov 14, 2024
6214450
reshuffle sidebars
rbalicki2 Nov 14, 2024
5d29372
add docs on conditional fetching
rbalicki2 Nov 14, 2024
7e4c3ff
add parameters docs
rbalicki2 Nov 14, 2024
8def7af
update pagination docs
rbalicki2 Nov 14, 2024
eb40343
link to moar from quickstart
rbalicki2 Nov 14, 2024
83feebf
update docs
rbalicki2 Nov 14, 2024
9049397
extract repository row into its own component
rbalicki2 Nov 15, 2024
1defe4c
simplify newsfeed pagination
rbalicki2 Nov 15, 2024
c2d4a6f
add documentatiaon about 3D and isConcreteType fields
rbalicki2 Nov 15, 2024
9f9ea34
oops - things were build using a compiler from the wrong commit
rbalicki2 Nov 15, 2024
8dc4e0e
update docs
rbalicki2 Nov 15, 2024
848afe6
update workflow
rbalicki2 Nov 15, 2024
4b45e14
fix: Add noUncheckedIndexAccess to tsconfig (#281)
lanesawyer Nov 15, 2024
223530d
log a message when a network response errors out
rbalicki2 Nov 15, 2024
3a8cf8f
adjusts vsCode extension to use npm instead of pnpm (#283)
saminoorsyed Nov 19, 2024
b334375
update dev workflow doc to reflect VSCode extension setup (#284)
saminoorsyed Nov 19, 2024
decbe83
replace std::Error with String (#285)
ch1ffa Nov 22, 2024
5e8e13d
update quickstart to note latest main
rbalicki2 Nov 23, 2024
14474de
do not specify dependency version for @isograph/disposable-types in i…
rbalicki2 Dec 3, 2024
61b4492
v0.3.0
rbalicki2 Dec 3, 2024
ae38787
remove unused import
rbalicki2 Dec 4, 2024
4699eef
remove unused import
rbalicki2 Dec 4, 2024
51fd3f7
onComplete takes a parameter (TClientFieldValue aka TResult)
rbalicki2 Dec 4, 2024
e042b66
remove unused imports
rbalicki2 Dec 4, 2024
92c6614
remove unused import
rbalicki2 Dec 21, 2024
06801b3
Merge branch 'generate-json-schema' of github.com:PatrykWalach/isogra…
PatrykWalach Dec 21, 2024
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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ jobs:
# # TODO do this less hackily
- name: Build
run: pnpm -r compile
- name: Build json schema
run: pnpm build-json-schema
- name: Download artifact isograph_cli-linux-x64
uses: actions/download-artifact@v4
with:
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
**/.docusaurus/**
**/dist/**
**/relay-crates/**
isograph-config-schema.json
44 changes: 44 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ notify-debouncer-full = "0.4.0"
pathdiff = "0.2.1"
pretty-duration = "0.1.1"
regex = "1.6.0"
schemars = { version="0.8.11", features=["indexmap1"] }
serde = "1.0.197"
serde_json = "1.0.108"
strum = { version = "0.25.0", features = ["derive"] }
Expand Down
3 changes: 3 additions & 0 deletions crates/common_lang_types/src/string_key_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ string_key_newtype!(DirectiveArgumentName);
// (client-defined linked fields do not exist, but will.)
string_key_newtype!(SelectableFieldName);

string_key_newtype!(ClientPointerFieldName);
string_key_conversion!(from: ClientPointerFieldName, to: SelectableFieldName);

string_key_newtype!(InputValueName);
string_key_conversion!(from: InputValueName, to: VariableName);
string_key_conversion!(from: InputValueName, to: FieldArgumentName);
Expand Down
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, SelectableServerFieldId, SelectionType, ServerFieldId, TypeAnnotation,
UnionVariant,
ClientFieldId, ClientPointerId, SelectableServerFieldId, SelectionType, ServerFieldId,
TypeAnnotation, UnionVariant,
};
use isograph_schema::{ClientType, FieldType, ValidatedSchema};

Expand Down Expand Up @@ -75,7 +75,7 @@ fn format_server_field_type(
fn format_field_definition(
schema: &ValidatedSchema,
name: &SelectableFieldName,
type_: &FieldType<ServerFieldId, ClientType<ClientFieldId>>,
type_: &FieldType<ServerFieldId, ClientType<ClientFieldId, ClientPointerId>>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry I meant to rebase just the commits that relate to generating the schema, i.e. we shouldn't have any changes related to ☝️

indentation_level: u8,
) -> String {
match type_ {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ pub fn get_artifact_path_and_content(
}

for user_written_client_field in schema.client_fields.iter().flat_map(|field| match field {
ClientType::ClientPointer(_) => todo!(),
ClientType::ClientField(field) => match field.variant {
ClientFieldVariant::UserWritten(_) => Some(field),
ClientFieldVariant::ImperativelyLoadedField(_) => None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ fn user_written_fields(
.client_fields
.iter()
.filter_map(|client_field| match client_field {
ClientType::ClientPointer(_) => todo!(),
ClientType::ClientField(client_field) => match client_field.variant {
ClientFieldVariant::UserWritten(info) => {
Some((client_field, info.user_written_component_variant))
Expand Down
17 changes: 16 additions & 1 deletion crates/graphql_lang_types/src/graphql_type_annotation.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{fmt, ops::Deref};

use common_lang_types::WithSpan;
use common_lang_types::{Span, WithSpan};

#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum GraphQLTypeAnnotation<TValue> {
Expand All @@ -18,6 +18,14 @@ impl<TValue> GraphQLTypeAnnotation<TValue> {
}
}

pub fn span(&self) -> &Span {
match self {
GraphQLTypeAnnotation::Named(named) => &named.0.span,
GraphQLTypeAnnotation::List(list) => list.0.span(),
GraphQLTypeAnnotation::NonNull(non_null) => non_null.span(),
}
}

pub fn inner_mut(&mut self) -> &mut TValue {
match self {
GraphQLTypeAnnotation::Named(named) => &mut named.0.item,
Expand Down Expand Up @@ -103,6 +111,13 @@ impl<TValue> GraphQLNonNullTypeAnnotation<TValue> {
}
}

pub fn span(&self) -> &Span {
match self {
GraphQLNonNullTypeAnnotation::Named(named) => &named.0.span,
GraphQLNonNullTypeAnnotation::List(list) => list.0.span(),
}
}

pub fn inner_mut(&mut self) -> &mut TValue {
match self {
GraphQLNonNullTypeAnnotation::Named(named) => &mut named.0.item,
Expand Down
98 changes: 72 additions & 26 deletions crates/isograph_compiler/src/field_directives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ use intern::string_key::Intern;
use isograph_lang_types::{
from_isograph_field_directive, ClientFieldDeclaration,
ClientFieldDeclarationWithUnvalidatedDirectives, ClientFieldDeclarationWithValidatedDirectives,
IsographFieldDirective, IsographSelectionVariant, LinkedFieldSelection, ScalarFieldSelection,
ServerFieldSelection,
ClientPointerDeclaration, ClientPointerDeclarationWithUnvalidatedDirectives,
ClientPointerDeclarationWithValidatedDirectives, IsographFieldDirective,
IsographSelectionVariant, LinkedFieldSelection, ScalarFieldSelection, ServerFieldSelection,
UnvalidatedSelection,
};
use isograph_schema::ProcessClientFieldDeclarationError;
use lazy_static::lazy_static;
Expand All @@ -20,19 +22,42 @@ pub fn validate_isograph_field_directives(
WithSpan<ClientFieldDeclarationWithValidatedDirectives>,
Vec<WithLocation<ProcessClientFieldDeclarationError>>,
> {
let ClientFieldDeclaration {
const_export_name,
parent_type,
client_field_name,
description,
selection_set,
directives,
variable_definitions,
definition_path,
dot,
field_keyword,
} = client_field.item;
let new_selecton_set = and_then_selection_set_and_collect_errors(
client_field.and_then(|client_field| {
let ClientFieldDeclaration {
const_export_name,
parent_type,
client_field_name,
description,
selection_set,
directives,
variable_definitions,
definition_path,
dot,
field_keyword,
} = client_field;

Ok(ClientFieldDeclarationWithValidatedDirectives {
const_export_name,
parent_type,
client_field_name,
description,
selection_set: validate_isograph_selection_set_directives(selection_set)?,
directives,
variable_definitions,
definition_path,
dot,
field_keyword,
})
})
}

pub fn validate_isograph_selection_set_directives(
selection_set: Vec<WithSpan<ServerFieldSelection<(), ()>>>,
) -> Result<
Vec<WithSpan<UnvalidatedSelection>>,
Vec<WithLocation<ProcessClientFieldDeclarationError>>,
> {
and_then_selection_set_and_collect_errors(
selection_set,
&|scalar_field_selection| {
if let Some(directive) =
Expand All @@ -55,23 +80,44 @@ pub fn validate_isograph_field_directives(
Ok(IsographSelectionVariant::Regular)
}
},
&|_linked_field_selection| Ok(IsographSelectionVariant::Regular),
)?;
Ok(WithSpan::new(
ClientFieldDeclarationWithValidatedDirectives {
&|_object_pointer_selection| Ok(IsographSelectionVariant::Regular),
)
}

#[allow(clippy::complexity)]
pub fn validate_isograph_pointer_directives(
client_pointer: WithSpan<ClientPointerDeclarationWithUnvalidatedDirectives>,
) -> Result<
WithSpan<ClientPointerDeclarationWithValidatedDirectives>,
Vec<WithLocation<ProcessClientFieldDeclarationError>>,
> {
client_pointer.and_then(|client_pointer| {
let ClientPointerDeclaration {
const_export_name,
parent_type,
client_field_name,
client_pointer_name,
description,
selection_set: new_selecton_set,
directives,
selection_set,
variable_definitions,
definition_path,
dot,
field_keyword,
},
client_field.span,
))
pointer_keyword,
to_type,
} = client_pointer;

Ok(ClientPointerDeclarationWithValidatedDirectives {
const_export_name,
parent_type,
client_pointer_name,
description,
selection_set: validate_isograph_selection_set_directives(selection_set)?,
variable_definitions,
definition_path,
dot,
pointer_keyword,
to_type,
})
})
}

fn and_then_selection_set_and_collect_errors<
Expand Down
20 changes: 18 additions & 2 deletions crates/isograph_compiler/src/isograph_literals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ use lazy_static::lazy_static;
use regex::Regex;

use crate::{
batch_compile::BatchCompileError, field_directives::validate_isograph_field_directives,
batch_compile::BatchCompileError,
field_directives::{validate_isograph_field_directives, validate_isograph_pointer_directives},
source_files::ContainsIso,
};

Expand Down Expand Up @@ -164,7 +165,22 @@ pub(crate) fn process_iso_literals(
Err(e) => errors.extend(e),
};
}
IsoLiteralExtractionResult::ClientPointerDeclaration(_) => todo!(),
IsoLiteralExtractionResult::ClientPointerDeclaration(
client_pointer_declaration,
) => {
match validate_isograph_pointer_directives(client_pointer_declaration) {
Ok(validated_client_pointer_declaration) => {
if let Err(e) = schema.process_client_pointer_declaration(
validated_client_pointer_declaration,
text_source,
) {
errors.push(e);
}
}
Err(e) => errors.extend(e),
};
}

IsoLiteralExtractionResult::EntrypointDeclaration(entrypoint_declaration) => schema
.entrypoints
.push((text_source, entrypoint_declaration)),
Expand Down
5 changes: 3 additions & 2 deletions crates/isograph_compiler/src/refetch_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use isograph_schema::{
generate_refetch_field_strategy, id_arguments, id_selection, id_top_level_arguments,
ClientField, ClientFieldVariant, ClientType, FieldType, ImperativelyLoadedFieldVariant,
ObjectTypeAndFieldName, RefetchStrategy, RequiresRefinement, SchemaObject,
UnvalidatedClientField, UnvalidatedSchema, NODE_FIELD_NAME, REFETCH_FIELD_NAME,
UnvalidatedClientField, UnvalidatedClientPointer, UnvalidatedSchema, NODE_FIELD_NAME,
REFETCH_FIELD_NAME,
};

use crate::batch_compile::BatchCompileError;
Expand All @@ -32,7 +33,7 @@ pub fn add_refetch_fields_to_objects(

fn add_refetch_field_to_object(
object: &mut SchemaObject,
client_fields: &mut Vec<ClientType<UnvalidatedClientField>>,
client_fields: &mut Vec<ClientType<UnvalidatedClientField, UnvalidatedClientPointer>>,
query_id: ServerObjectId,
) -> Option<Result<(), BatchCompileError>> {
match object
Expand Down
1 change: 1 addition & 0 deletions crates/isograph_config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ license = { workspace = true}

[dependencies]
common_lang_types = { path = "../common_lang_types" }
schemars = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
colorize = { workspace = true }
Expand Down
Loading
Loading