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

[WPFM-1880] Upgrade dependencies as part of React 19 upgrade #7

Merged
merged 11 commits into from
Dec 13, 2024
Merged
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
659 changes: 525 additions & 134 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ edition = "2021"
crate-type = ["cdylib", "rlib"]

[dependencies]
swc_core = { version = "0.90.30", features = ["ecma_plugin_transform"] }
swc_ecma_ast = "^0.112.6"
swc_ecma_visit = "^0.98.7"
swc_core = { version = "0.106.3", features = ["ecma_plugin_transform"] }
swc_ecma_ast = "0.121.1"
swc_ecma_visit = "0.107.0"
swc_ecma_parser = "0.152.1"
graphql_tag = { path = "./transforms/graphql_tag" }
unique_identifier = { path = "./transforms/unique_identifier" }
serde = "1.0.193"
Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Rishabh Chawla

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ SWC plugin alternative to `babel-plugin-graphql-tag`
npm install -D graphql-tag-swc-plugin
```

## Building and deploying to Scorebet repository

1. Build locally
```
npm run build
```
2. Create a local file `/.token` containing a personal access token with publish package scope for the scorebet organization
3. Publish the package
```
npm run publish
```

## Usage

### SWC
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "@scorebet/graphql-tag-swc-plugin",
"version": "1.0.1",
"description": "SWC plugin to expand gql tags at build time",
"license": "ISC",
"version": "1.1.1",
"keywords": [
"swc-plugin",
"swc",
"graphql"
],
"repository": "github:rishabh3112/graphql-tag-swc-plugin",
"main": "graphql_tag_swc_plugin.wasm",
"scripts": {
"build": "cargo build-wasi --release && cp target/wasm32-wasi/release/graphql_tag_swc_plugin.wasm .",
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use graphql_tag::structs::{GraphQLTagConfig, TransformVisitor};
use unique_identifier::UniqueIdentifierVisitor;

fn get_syntax() -> Syntax {
// TODO: use EsSyntax instead
Syntax::Es(EsConfig {
jsx: true,
..Default::default()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import gql from 'graphql-tag';

const foo = gql`{foo}`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import gql from 'graphql-tag';
const foo = {
"kind": "Document",
"definitions": [
{
"kind": "OperationDefinition",
"directives": [],
"variableDefinitions": [],
"operation": "query",
"selectionSet": {
"kind": "SelectionSet",
"selections": [
{
"kind": "Field",
"name": {
"kind": "Name",
"value": "foo"
},
"arguments": [],
"directives": []
}
]
}
}
],
"loc": {
"start": 0,
"end": 5,
"source": {
"body": "{foo}"
}
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import gql from 'graphql-tag';
const foo = {
"kind": "Document",
"definitions": [
{
"kind": "OperationDefinition",
"directives": [],
"variableDefinitions": [],
"operation": "query",
"selectionSet": {
"kind": "SelectionSet",
"selections": [
{
"kind": "Field",
"name": {
"kind": "Name",
"value": "foo"
},
"arguments": [],
"directives": []
}
]
}
}
],
"loc": {
"start": 0,
"end": 5,
"source": {
"body": "{foo}"
}
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import gql from 'graphql-tag';

const foo = gql`query($foo: String!) {foo1}`;
55 changes: 55 additions & 0 deletions tests/graphql_tag/definations/operation/unnamed_query/output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import gql from 'graphql-tag';
const foo = {
"kind": "Document",
"definitions": [
{
"kind": "OperationDefinition",
"directives": [],
"variableDefinitions": [
{
"kind": "VariableDefinition",
"directives": [],
"variable": {
"kind": "Variable",
"name": {
"kind": "Name",
"value": "foo"
}
},
"type": {
"kind": "NonNullType",
"type": {
"kind": "NamedType",
"name": {
"kind": "Name",
"value": "String"
}
}
}
}
],
"operation": "query",
"selectionSet": {
"kind": "SelectionSet",
"selections": [
{
"kind": "Field",
"name": {
"kind": "Name",
"value": "foo1"
},
"arguments": [],
"directives": []
}
]
}
}
],
"loc": {
"start": 0,
"end": 27,
"source": {
"body": "query($foo: String!) {foo1}"
}
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import gql from 'graphql-tag';
const foo = {
"kind": "Document",
"definitions": [
{
"kind": "OperationDefinition",
"directives": [],
"variableDefinitions": [
{
"kind": "VariableDefinition",
"directives": [],
"variable": {
"kind": "Variable",
"name": {
"kind": "Name",
"value": "foo"
}
},
"type": {
"kind": "NonNullType",
"type": {
"kind": "NamedType",
"name": {
"kind": "Name",
"value": "String"
}
}
}
}
],
"operation": "query",
"selectionSet": {
"kind": "SelectionSet",
"selections": [
{
"kind": "Field",
"name": {
"kind": "Name",
"value": "foo1"
},
"arguments": [],
"directives": []
}
]
}
}
],
"loc": {
"start": 0,
"end": 25,
"source": {
"body": "query($foo:String!){foo1}"
}
}
};
10 changes: 5 additions & 5 deletions transforms/graphql_tag/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ edition = "2021"

[dependencies]
apollo-parser = "0.7.5"
swc_common = { version = "*", features = ["concurrent"] }
swc_ecma_ast = "^0.112.6"
swc_ecma_visit = "^0.98.7"
swc_ecma_parser = "^0.143.10"
swc_core = { version = "0.90.30", features = ["ecma_plugin_transform"] }
swc_common = { version = "0.40.1", features = ["concurrent"] }
swc_ecma_ast = "0.121.1"
swc_ecma_visit = "0.107.0"
swc_ecma_parser = "0.152.1"
swc_core = { version = "0.106.3", features = ["ecma_plugin_transform"] }
regex = "1"
serde = "1.0.193"
serde_json = "1.0.108"
Expand Down
13 changes: 11 additions & 2 deletions transforms/graphql_tag/src/parser/nodes/definitions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ mod operation;
use fragment::create_fragment_definition;
use operation::create_operation_definition;

pub fn create_definition(definition: Definition, span: Span) -> Option<ExprOrSpread> {
pub fn create_definition(
definition: Definition,
span: Span,
assert_definition_name: bool,
) -> Option<ExprOrSpread> {
if assert_definition_name {
definition.name().expect("GraphQL query must have name.");
}
let def_expr = match definition {
Definition::FragmentDefinition(frag_def) => create_fragment_definition(frag_def, span),
Definition::OperationDefinition(operation_def) => {
Expand Down Expand Up @@ -42,8 +49,10 @@ pub fn create_definition(definition: Definition, span: Span) -> Option<ExprOrSpr

pub fn create_definitions(definitions: CstChildren<Definition>, span: Span) -> Expr {
let mut all_definitions = vec![];
let is_multiple_definitions = definitions.clone().count() > 1;

for def in definitions {
all_definitions.push(create_definition(def, span));
all_definitions.push(create_definition(def, span, is_multiple_definitions));
}

Expr::Array(ArrayLit {
Expand Down
17 changes: 12 additions & 5 deletions transforms/graphql_tag/src/parser/nodes/definitions/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ use crate::parser::{

pub fn create_operation_definition(definition: OperationDefinition, span: Span) -> Box<Expr> {
let kind = get_key_value_node("kind".into(), "OperationDefinition".into());
let name = get_key_value_node(
"name".into(),
create_name(definition.name().unwrap().text().as_str().into(), span),
);

let variable_definitions = get_key_value_node(
"variableDefinitions".into(),
create_variable_definitions(definition.variable_definitions(), span),
Expand All @@ -34,9 +31,19 @@ pub fn create_operation_definition(definition: OperationDefinition, span: Span)

let mut opr_def = ObjectLit {
span,
props: vec![kind, name, directives, variable_definitions, operation],
props: vec![kind, directives, variable_definitions, operation],
};

if definition.name().is_some() {
opr_def.props.insert(
1,
get_key_value_node(
"name".into(),
create_name(definition.name().unwrap().text().as_str().into(), span),
),
);
}

if definition.selection_set().is_some() {
let selection_set = get_key_value_node(
"selectionSet".into(),
Expand Down
9 changes: 6 additions & 3 deletions transforms/graphql_tag/src/parser/nodes/document/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::HashMap;

// libs
use apollo_parser::cst::Document;
use swc_common::{comments::Comments, BytePos, Span};
use swc_common::{comments::Comments, BytePos, Span, SyntaxContext};
use swc_ecma_ast::*;

// helpers
Expand Down Expand Up @@ -44,7 +44,7 @@ pub fn create_document<C: Comments>(
let member_expr_for_definitions = MemberExpr {
span,
obj: _expression,
prop: MemberProp::Ident(Ident::new("definitions".into(), span)),
prop: MemberProp::Ident(IdentName::new("definitions".into(), span)),
};

all_expressions.push(ExprOrSpread {
Expand All @@ -58,23 +58,26 @@ pub fn create_document<C: Comments>(
callee: Callee::Expr(Box::new(Expr::Member(MemberExpr {
span,
obj: Box::new(definitions_expr.clone()),
prop: MemberProp::Ident(Ident::new("concat".into(), span)),
prop: MemberProp::Ident(IdentName::new("concat".into(), span)),
}))),
args: all_expressions,
type_args: None,
ctxt: SyntaxContext::default(),
});

let unique_fn_call_expr = Expr::Call(CallExpr {
span: Span::with_lo(&span, span.lo() + BytePos(1)),
callee: Callee::Expr(Box::new(Expr::Ident(Ident::new(
unique_fn_name.clone().into(),
span,
SyntaxContext::default(),
)))),
args: vec![ExprOrSpread {
spread: None,
expr: Box::new(concat_definitions_expr.clone()),
}],
type_args: None,
ctxt: SyntaxContext::default(),
});

let definitions = get_key_value_node(
Expand Down
Loading
Loading