GraphQL-PPX Compatibility Validation
Objective
Validate graphql-ppx compatibility with Melange 5.0 and establish type-safe GraphQL query generation pipeline.
Background
graphql-ppx (v1.2.2, last updated 2021) needs testing with Melange 5.0. If incompatible, we'll evaluate alternatives like ppx_graphql.
Tasks
-
Install graphql_ppx from OPAM -
Create test queries with graphql-ppx -
Verify ppxlib version compatibility -
Test with exported PostGraphile schema -
Configure dune for PPX preprocessing -
Validate generated types with Melange -
Document any workarounds needed -
Create fallback plan if incompatible
Test Implementation
(* test/GraphQLTest.re *)
module GetUser = [%graphql
{|
query GetUser($id: ID\!) {
user(id: $id) {
id
email
name
}
}
|}
];
let testQuery = () => {
let query = GetUser.make(~id="1", ());
Js.log(query##variables);
};
Dune Configuration
(library
(name graphql_test)
(libraries melange.js graphql_ppx melange_apollo)
(modes melange)
(preprocess (pps graphql_ppx melange.ppx)))
Acceptance Criteria
-
PPX processes GraphQL queries without errors -
Generated types work with Melange -
Can use types with Apollo bindings -
Schema file loading works -
Variables properly typed -
Fragments supported
Alternative Approaches
Option A: ppx_graphql
opam install ppx_graphql
Option B: Manual Types
(* If PPX fails, use manual approach *)
type userQuery = {
id: string,
email: string,
name: option(string),
};
let query = {|
query GetUser($id: ID\!) {
user(id: $id) { id email name }
}
|};
Option C: Generate Types from Schema
# Use graphql-codegen with custom templates
npm run codegen:types
Version Compatibility Matrix
Component | Required | Current | Status |
---|---|---|---|
Melange | 5.0+ | 5.0 | |
ppxlib | <0.36.0 | ? | Test |
graphql_ppx | 1.2.2 | 1.2.2 | Test |
OCaml | 4.06+ | 5.3 |
Testing Strategy
- Simple query test
- Query with variables
- Mutation test
- Fragment test
- Union types test
- Interface types test
🟡 High
Priority: Can work around if needed, but impacts DX significantly.
Estimated Effort: 1-2 days
Risk Mitigation
If graphql-ppx fails:
- Try ppx_graphql (2 hours)
- Use manual types (4 hours)
- Build codegen solution (1 day)
- Use PostGraphile client (2 hours)
Dependencies
CI Validation
-
PPX preprocessing succeeds -
Type checking passes -
Generated code compiles