forked from teamwalnut/graphql-ppx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
3 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,3 @@ | ||
# hello-ppx-esy | ||
# graphql_ppx_re | ||
|
||
A project that includes the minimum configuration for a [ppx](https://blog.hackages.io/reasonml-ppx-8ecd663d5640) project using Reason and [Esy](https://github.com/esy-ocaml/esy). | ||
|
||
It implements a very basic ppx that transforms the `[%test]` extension into the number literal `42`. | ||
|
||
So, the code: | ||
|
||
```reason | ||
let fourtyTwo = string_of_int([%test]); | ||
``` | ||
|
||
Is transformed into: | ||
|
||
```reason | ||
let fourtyTwo = string_of_int(42); | ||
``` | ||
|
||
## Usage | ||
|
||
You need Esy, you can install the beta using [npm](https://nodejs.org/en/download/): | ||
|
||
% npm install -g esy@latest | ||
|
||
Then you can install the project dependencies using: | ||
|
||
% esy install | ||
|
||
Then build the project dependencies along with the project itself: | ||
|
||
% esy build | ||
|
||
After building, you should see an executable in `_esy/default/build/default/.ppx/test_ppx/ppx.exe`. | ||
This will be the binary used by BuckleScript in the example below. | ||
|
||
## Example | ||
|
||
You can see an example of usage in a BuckleScript project in the `/example` folder. | ||
The most relevant point is the `ppx-flags` in `example/bsconfig.json`, that is pointing to the ppx executable: | ||
|
||
``` | ||
"ppx-flags": [ | ||
"../_esy/default/build/default/.ppx/test_ppx/ppx.exe --as-ppx" | ||
], | ||
``` | ||
|
||
To compile the example: | ||
|
||
% esy install | ||
|
||
Then you can run | ||
|
||
% yarn build | ||
|
||
or | ||
|
||
% npm run build | ||
|
||
At that point, you should see the file `src/Index.bs.js` with the following output: | ||
|
||
```javascript | ||
// Generated by BUCKLESCRIPT VERSION 4.0.7, PLEASE EDIT WITH CARE | ||
'use strict'; | ||
|
||
|
||
var fourtyTwo = String(42); | ||
|
||
console.log(fourtyTwo); | ||
|
||
exports.fourtyTwo = fourtyTwo; | ||
/* fourtyTwo Not a pure module */ | ||
``` | ||
> Experiments with graphql_ppx and Reason |