Skip to content

Commit

Permalink
Move compiler to separate package (#91)
Browse files Browse the repository at this point in the history
* Move nova compiler to separate package

* Add compiler package

* Change files

* Add README.md
  • Loading branch information
Markionium authored Feb 20, 2024
1 parent d5b1244 commit 39facf2
Show file tree
Hide file tree
Showing 15 changed files with 230 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Add new @nova/graphql-compiler package to examples",
"packageName": "@nova/examples",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Move nova compiler to separate package",
"packageName": "@nova/graphql-compiler",
"email": "[email protected]",
"dependentChangeType": "patch"
}
7 changes: 7 additions & 0 deletions change/@nova-react-bc1eadc6-de4f-4c56-91ce-863cd0b6ec94.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "major",
"comment": "Move nova compiler to separate package",
"packageName": "@nova/react",
"email": "[email protected]",
"dependentChangeType": "patch"
}
1 change: 1 addition & 0 deletions packages/examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
},
"dependencies": {
"@nova/react": "1.6.0",
"@nova/graphql-compiler": "1.0.0",
"@nova/react-test-utils": "4.1.0",
"@nova/types": "1.4.0",
"graphql": "^15.5.0",
Expand Down
21 changes: 21 additions & 0 deletions packages/nova-graphql-compiler/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# @nova/graphql-compiler

This package contains the compiler that used to be available with `@nova/react`. This compiler is just here for backwards compatibility. We recommend using [`duct-tape-compiler`](https://github.com/microsoft/graphitation/tree/main/packages/apollo-react-relay-duct-tape-compiler) or the latest [`relay-compiler`](https://relay.dev/docs/getting-started/installation-and-setup/#set-up-the-compiler) instead.

## Migration from the embedded compiler inside @nova/react

If you used the embedded compiler inside `@nova/react` you can now use this package instead. This should be a drop in replacement. Upgrading `@nova/react` to version 2.0.0 will remove the embedded compiler. You can then add this package to your project your scripts should keep working.

## Installation

Add `@nova/graphql-compiler` to your project.

Then inside your package.json add the compiler to your `scripts`:

```json
{
"scripts": {
"generate": "nova-graphql-compiler"
}
}
```
36 changes: 36 additions & 0 deletions packages/nova-graphql-compiler/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "@nova/graphql-compiler",
"license": "MIT",
"version": "1.0.0",
"main": "./src/cli.js",
"scripts": {
"lint": "monorepo-scripts lint",
"test": "monorepo-scripts test",
"just": "monorepo-scripts"
},
"bin": {
"nova-graphql-compiler": "./src/cli.js"
},
"dependencies": {
"relay-runtime": "12.0.0",
"graphql": "^15.5.0",
"relay-compiler": "^12.0.0",
"relay-compiler-language-graphitation": "^0.8.2",
"yargs": "^16.2.0"
},
"devDependencies": {
"monorepo-scripts": "*"
},
"repository": {
"type": "git",
"url": "https://github.com/microsoft/nova-facade.git",
"directory": "packages/nova-graphql-compiler"
},
"sideEffects": false,
"access": "public",
"exports": {
".": {
"require": "./src/cli.js"
}
}
}
7 changes: 7 additions & 0 deletions packages/nova-graphql-compiler/src/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": ["../../.eslintrc.json"],
"root": true,
"rules": {
"@typescript-eslint/no-var-requires": ["off"]
}
}
25 changes: 25 additions & 0 deletions packages/nova-graphql-compiler/src/__fixtures__/schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
type Mutation {
feedbackLike(input: FeedbackLikeInput!): FeedbackLikeMutationResult!
}
type Query {
feedback(id: ID!): Feedback!
}

type FeedbackLikeMutationResult {
feedback: Feedback!
}

type Feedback {
id: ID!
message: Message!
doesViewerLike: Boolean!
}

type Message {
text: String!
}

input FeedbackLikeInput {
feedbackId: ID!
doesViewerLike: Boolean!
}
11 changes: 11 additions & 0 deletions packages/nova-graphql-compiler/src/__fixtures__/src/Example.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { graphql } from "@nova/react";

graphql`
fragment Example_feedbackFragment on Feedback {
id
message {
text
}
doesViewerLike
}
`;

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

23 changes: 23 additions & 0 deletions packages/nova-graphql-compiler/src/__snapshots__/cli.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`cli generates files 1`] = `
"/* tslint:disable */
/* eslint-disable */
// @ts-nocheck
;
import { FragmentRefs } from "@graphitation/apollo-react-relay-duct-tape";
export type Example_feedbackFragment = {
readonly id: string;
readonly message: {
readonly text: string;
};
readonly doesViewerLike: boolean;
readonly " $refType": "Example_feedbackFragment";
};
export type Example_feedbackFragment$data = Example_feedbackFragment;
export type Example_feedbackFragment$key = {
readonly " $data"?: Example_feedbackFragment$data | undefined;
readonly " $fragmentRefs": FragmentRefs<"Example_feedbackFragment">;
};
"
`;
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/usr/bin/env node

const path = require("path");
const yargs = require("yargs");

const { relayCompiler } = require("relay-compiler");
Expand Down
40 changes: 40 additions & 0 deletions packages/nova-graphql-compiler/src/cli.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const { spawnSync } = require("child_process");
const { readFile, rm } = require("fs/promises");
const path = require("path/posix");

describe("cli", () => {
it("generates files", async () => {
// Remove old generated files if they exist
await rm(path.join(__dirname, "__fixtures__/src/__generated__"), {
recursive: true,
force: true,
});

// Run the compiler
spawnSync(
"./src/cli.js",
[
"--schema",
"./src/__fixtures__/schema.graphql",
"--src",
"./src/__fixtures__/src",
"--watchman",
"false",
],
{
stdio: "inherit",
},
);

// Read the generated files
const generatedFiles = await readFile(
path.join(
__dirname,
"__fixtures__/src/__generated__/Example_feedbackFragment.graphql.ts",
),
"utf8",
);

expect(generatedFiles).toMatchSnapshot();
});
});
8 changes: 1 addition & 7 deletions packages/nova-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
"types": "monorepo-scripts types",
"just": "monorepo-scripts"
},
"bin": {
"nova-graphql-compiler": "./src/graphql/cli.js"
},
"peerDependencies": {
"react": "^17.0.2 || ^18",
"@types/react": "^17.0.2 || ^18",
Expand All @@ -21,10 +18,7 @@
"dependencies": {
"@nova/types": "^1.4.0",
"graphql": "^15.5.0",
"invariant": "^2.2.4",
"relay-compiler": "^10.1.3",
"relay-compiler-language-graphitation": "^0.8.2",
"yargs": "^16.2.0"
"invariant": "^2.2.4"
},
"devDependencies": {
"@graphitation/graphql-js-tag": "^0.9.0",
Expand Down
29 changes: 26 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3332,9 +3332,9 @@
"@types/react" "^17"

"@types/react@>=16":
version "18.0.28"
resolved "https://registry.yarnpkg.com/@types/react/-/react-18.0.28.tgz#accaeb8b86f4908057ad629a26635fe641480065"
integrity sha512-RD0ivG1kEztNBdoAK7lekI9M+azSnitIn85h4iOiaLjaTrMjzslhaqCGaI4IyCJ1RljWiLCEu4jyrLLgqxBTew==
version "18.2.47"
resolved "https://registry.yarnpkg.com/@types/react/-/react-18.2.47.tgz#85074b27ab563df01fbc3f68dc64bf7050b0af40"
integrity sha512-xquNkkOirwyCgoClNk85BjP+aqnIS+ckAJ8i37gAbDs14jfW/J23f2GItAf33oiUPQnqNMALiFeoM9Y5mbjpVQ==
dependencies:
"@types/prop-types" "*"
"@types/scheduler" "*"
Expand Down Expand Up @@ -9313,6 +9313,29 @@ relay-compiler@^10.1.3:
signedsource "^1.0.0"
yargs "^15.3.1"

relay-compiler@^12.0.0:
version "12.0.0"
resolved "https://registry.yarnpkg.com/relay-compiler/-/relay-compiler-12.0.0.tgz#9f292d483fb871976018704138423a96c8a45439"
integrity sha512-SWqeSQZ+AMU/Cr7iZsHi1e78Z7oh00I5SvR092iCJq79aupqJ6Ds+I1Pz/Vzo5uY5PY0jvC4rBJXzlIN5g9boQ==
dependencies:
"@babel/core" "^7.14.0"
"@babel/generator" "^7.14.0"
"@babel/parser" "^7.14.0"
"@babel/runtime" "^7.0.0"
"@babel/traverse" "^7.14.0"
"@babel/types" "^7.0.0"
babel-preset-fbjs "^3.4.0"
chalk "^4.0.0"
fb-watchman "^2.0.0"
fbjs "^3.0.0"
glob "^7.1.1"
immutable "~3.7.6"
invariant "^2.2.4"
nullthrows "^1.1.1"
relay-runtime "12.0.0"
signedsource "^1.0.0"
yargs "^15.3.1"

[email protected]:
version "10.1.3"
resolved "https://registry.yarnpkg.com/relay-runtime/-/relay-runtime-10.1.3.tgz#1d7bfe590b50cd7f18f6d1c0f20df71fe5bb451a"
Expand Down

0 comments on commit 39facf2

Please sign in to comment.