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

Use task scheduler to process optimistic responses and execute error rollback. #3

Open
wants to merge 4 commits into
base: main-atl
Choose a base branch
from
Open
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
9 changes: 5 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ jobs:
main-release:
name: Publish to NPM
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.repository == 'facebook/relay'
if: github.event_name == 'push' && github.repository == 'atlassian-forks/relay'
needs: [js-tests, js-lint, typecheck, build-tests, build-compiler]
steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -262,7 +262,7 @@ jobs:
chmod +x macos-arm64/relay

- name: Build latest (main) version
if: github.ref == 'refs/heads/main'
if: github.ref == 'refs/heads/main-atl'
run: yarn gulp mainrelease
env:
RELEASE_COMMIT_SHA: ${{ github.sha }}
Expand All @@ -272,11 +272,12 @@ jobs:
run: yarn gulp release

- name: Publish to npm
if: github.ref == 'refs/heads/main' || github.ref_type == 'tag' && startsWith(github.ref_name, 'v')
if: github.ref == 'refs/heads/main-atl' || github.ref_type == 'tag' && startsWith(github.ref_name, 'v')
run: |
for pkg in dist/*; do
npm publish "$pkg" ${TAG}
done
env:
TAG: ${{ github.ref == 'refs/heads/main' && '--tag=main' || ((contains(github.ref_name, '-rc.') && '--tag=dev') || '' )}}
TAG: ${{ github.ref == 'refs/heads/main-atl' && '--tag=main-atl' || ((contains(github.ref_name, '-rc.') && '--tag=dev') || '' )}}
NPM_REGISTRY: ${{secrets.REGISTRY}}
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
27 changes: 27 additions & 0 deletions compiler/Cargo.lock

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

25 changes: 25 additions & 0 deletions compiler/crates/persisted-mocks/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# @generated by autocargo from //relay/oss/crates/relay-docblock:[relay-docblock,relay-docblock_parse_test,relay-to_schema_test]
[package]
name = "persisted-mocks"
version = "0.0.0"
authors = ["Atlassian"]
edition = "2021"
license = "MIT"

[dependencies]
clap = { version = "3.2.25", features = ["derive", "env", "regex", "unicode", "wrap_help"] }
common = { path = "../common" }
intern = { path = "../intern" }
log = { version = "0.4.17", features = ["kv_unstable", "kv_unstable_std"] }
relay-compiler = { path = "../relay-compiler" }
relay-codegen = { path = "../relay-codegen" }
relay-transforms = { path = "../relay-transforms" }
signedsource = {path = "../signedsource"}
serde_json = { version = "1.0.100", features = ["float_roundtrip", "unbounded_depth"] }
serde = { version = "1.0.185", features = ["derive", "rc"] }
relay-lsp = { path = "../relay-lsp" }
schema = { path = "../schema" }
schema-documentation = { path = "../schema-documentation" }
simplelog = "0.10.0"
thiserror = "1.0.43"
tokio = { version = "1.29.1", features = ["full", "test-util", "tracing"] }
8 changes: 8 additions & 0 deletions compiler/crates/persisted-mocks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# relay_docblock

Extract and valdiate Relay-specific information from Docblocks.

## Development

Note that snapshots can be updated by running tests with the
`UPDATE_SNAPSHOTS=1` environment variable set.
61 changes: 61 additions & 0 deletions compiler/crates/persisted-mocks/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

use relay_codegen::QueryID;
use relay_compiler::Artifact;
use relay_compiler::ArtifactContent;
use relay_compiler::ProjectConfig;
use relay_transforms::Programs;
use schema::SDLSchema;

#[derive(serde::Serialize)]
struct QueryForMock {
signature: &'static str,
id: String,
operation: String,
}

pub fn generate_persisted_mocks(
project_config: &ProjectConfig,
_schema: &SDLSchema,
_programs: &Programs,
artifacts: &[Artifact],
) -> Vec<Artifact> {
let mut extra = vec![];
if let Some(folder) = &project_config.extra_artifacts_output {
for artifact in artifacts {
if let ArtifactContent::Operation {
text: Some(text),
id_and_text_hash: Some(QueryID::Persisted { id, .. }),
normalization_operation,
..
} = &artifact.content
{
let name = normalization_operation.name.item;
let full_path = folder.join(format!("{name}.json"));
let query = QueryForMock {
signature: signedsource::SIGNING_TOKEN,
id: id.clone(),
operation: text.clone(),
};
let str = serde_json::to_string_pretty(&query).unwrap();
let str = signedsource::sign_file(str.as_str());

let new_artifact = Artifact {
content: ArtifactContent::Generic {
content: str.as_bytes().to_vec(),
},
artifact_source_keys: artifact.artifact_source_keys.clone(),
path: full_path,
source_file: artifact.source_file,
};
extra.push(new_artifact);
}
}
}
extra
}
5 changes: 5 additions & 0 deletions compiler/crates/relay-bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ common = { path = "../common" }
intern = { path = "../intern" }
log = { version = "0.4.17", features = ["kv_unstable", "kv_unstable_std"] }
relay-compiler = { path = "../relay-compiler" }
relay-codegen = { path = "../relay-codegen" }
signedsource = {path = "../signedsource"}
serde_json = { version = "1.0.100", features = ["float_roundtrip", "unbounded_depth"] }
serde = { version = "1.0.185", features = ["derive", "rc"] }
relay-lsp = { path = "../relay-lsp" }
persisted-mocks = { path = "../persisted-mocks" }
schema = { path = "../schema" }
schema-documentation = { path = "../schema-documentation" }
simplelog = "0.10.0"
Expand Down
3 changes: 3 additions & 0 deletions compiler/crates/relay-bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ async fn handle_compiler_command(command: CompileCommand) -> Result<(), Error> {
)
}));

// Atlassian: Output id -> query text for testing / mocking usage
config.generate_extra_artifacts = Some(Box::new(persisted_mocks::generate_persisted_mocks));

config.file_source_config = if should_use_watchman() {
FileSourceKind::Watchman
} else {
Expand Down
30 changes: 28 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,24 @@ builds.forEach(build => {
.pipe(gulp.dest(path.join(DIST, build.package, 'lib')));
},
function copyPackageJSON() {
return gulp
const stream = gulp
.src(['package.json'], {
cwd: path.join(PACKAGES, build.package),
})
.pipe(gulp.dest(path.join(DIST, build.package)));
stream.on('end', () => {
const pkgJson = JSON.parse(
fs
.readFileSync(path.join(DIST, build.package, 'package.json'))
.toString(),
);
pkgJson.name = 'atl-' + pkgJson.name;
fs.writeFileSync(
path.join(DIST, build.package, 'package.json'),
JSON.stringify(pkgJson, null, 2),
);
});
return stream;
},
);
});
Expand Down Expand Up @@ -362,11 +375,24 @@ const relayCompiler = gulp.parallel(
.pipe(gulp.dest(path.join(DIST, 'relay-compiler')));
},
function copyPackageFiles() {
return gulp
const stream = gulp
.src(['README.md', 'package.json', 'cli.js', 'index.js'], {
cwd: path.join(PACKAGES, 'relay-compiler'),
})
.pipe(gulp.dest(path.join(DIST, 'relay-compiler')));
stream.on('end', () => {
const pkg = JSON.parse(
fs
.readFileSync(path.join(DIST, 'relay-compiler', 'package.json'))
.toString(),
);
pkg.name = 'atl-' + pkg.name;
fs.writeFileSync(
path.join(DIST, 'relay-compiler', 'package.json'),
JSON.stringify(pkg, null, 2),
);
});
return stream;
},
function copyCompilerBins() {
return gulp
Expand Down
30 changes: 17 additions & 13 deletions packages/relay-runtime/store/OperationExecutor.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,15 @@ class Executor<TMutation: MutationParameters> {
});

if (optimisticConfig != null) {
this._processOptimisticResponse(
optimisticConfig.response != null
? {data: optimisticConfig.response}
: null,
optimisticConfig.updater,
false,
);
this._schedule(() => {
this._processOptimisticResponse(
optimisticConfig.response != null
? {data: optimisticConfig.response}
: null,
optimisticConfig.updater,
false,
);
});
}
}

Expand Down Expand Up @@ -342,12 +344,14 @@ class Executor<TMutation: MutationParameters> {
}

_error(error: Error): void {
this.cancel();
this._sink.error(error);
this._log({
name: 'execute.error',
executeId: this._executeId,
error,
this._schedule(() => {
this.cancel();
this._sink.error(error);
this._log({
name: 'execute.error',
executeId: this._executeId,
error,
});
});
}

Expand Down
Loading
Loading