Git Product home page Git Product logo

aos-graphql's Introduction

aos-graphql

Caution

This is an experimental repo, and under active development

As such, this repo may become out-of-date and may not work out-of-the-box, and no Tier 1 support from the AO dev team is offered for this repository.

This is a PoC for implementing the GraphQL Runtime in ao.

Goals

The goal is to demonstrate a functioning GraphQL server running inside an ao Process. This involves receive a GraphQL operation, parsing it, resolving it, then returning the result as a Lua table.

Prerequisites

  • ao dev-cli 0.1.3
  • cmake and make
  • If running the repl.js, you'll need NodeJS 22+ and npm

Getting Started

Initialize the aos submodule using git submodule update --init. You can update the submodule to latest by running git submodule update --remote.

Then either use cmake, or if you have npm, simply run npm run build to produce the wasm with a built-in graphql runtime implementation

If using the repl.js you'll need to also install dependencies using npm i

How it works

The Lua implementation of the GraphQL runtime is located in the graphql folder.

The Lua implementation depends on a a pure C implementation of a GraphQL operation parser, libgraphqlparser, copied from The GraphQL foundation here.

Lua requires bindings in order to invoke the C parser, which are implemented here

When running the root cmake:

  • The C implementation is compiled into a static library (.a)
  • The Lua bindings are then compiled, along with the compiled C implementation into a static library .a
  • The Lua implementation of the GraphQL runtime, along with the .a are copied in aos/process/graphql and aos/process/libs
  • The ao dev-cli is used to build the aos process code into a process.wasm, which is then copied to the root of the repo, to be loaded by the repl.js, if desired.

Sample GraphQL

A sample graphql server is implemented in server.lua and can be hotloaded via the repl.js using executing sample-gql

Known Outstanding Issues

aos-graphql's People

Contributors

tillathehun0 avatar

Watchers

Peter Farber avatar  avatar

aos-graphql's Issues

bug: variables and arguments failing to parse

Reproduce

Load the sample graphql server using sample-gql in the repl.js, then run the following expression:

ao.server('query GetPerson ($id: ID!)  { person(id: $id) { id, firstName, lastName, age } }', { id = 'id-1' })

The following error will be produced:

Error:  RuntimeError: null function or function signature mismatch
    at process.wasm.CVisitorBridge::endVisitStringValue(facebook::graphql::ast::StringValue const&) (wasm://wasm/process.wasm-004d2fda:wasm-function[1091]:0x9d87d)
    at process.wasm.facebook::graphql::ast::StringValue::accept(facebook::graphql::ast::visitor::AstVisitor*) const (wasm://wasm/process.wasm-004d2fda:wasm-function[1172]:0xa4ca1)
    at process.wasm.facebook::graphql::ast::Argument::accept(facebook::graphql::ast::visitor::AstVisitor*) const (wasm://wasm/process.wasm-004d2fda:wasm-function[1165]:0xa41a9)
    at process.wasm.facebook::graphql::ast::Field::accept(facebook::graphql::ast::visitor::AstVisitor*) const (wasm://wasm/process.wasm-004d2fda:wasm-function[1164]:0xa3f4a)
    at process.wasm.facebook::graphql::ast::SelectionSet::accept(facebook::graphql::ast::visitor::AstVisitor*) const (wasm://wasm/process.wasm-004d2fda:wasm-function[1163]:0xa3d0e)
    at process.wasm.facebook::graphql::ast::OperationDefinition::accept(facebook::graphql::ast::visitor::AstVisitor*) const (wasm://wasm/process.wasm-004d2fda:wasm-function[1161]:0xa39b7)
    at process.wasm.facebook::graphql::ast::Document::accept(facebook::graphql::ast::visitor::AstVisitor*) const (wasm://wasm/process.wasm-004d2fda:wasm-function[1160]:0xa36f1)
    at process.wasm.graphql_parse (wasm://wasm/process.wasm-004d2fda:wasm-function[1027]:0x8fdee)
    at process.wasm.luaD_precall (wasm://wasm/process.wasm-004d2fda:wasm-function[116]:0xbb1f)
    at process.wasm.luaV_execute (wasm://wasm/process.wasm-004d2fda:wasm-function[266]:0x2fff0)
node:internal/process/promises:391
    triggerUncaughtException(err, true /* fromPromise */);

Developer Notes

WebAssembly enforces strict type checking for function signatures. This means that the number, types of arguments, and return types must match exactly. If there's any discrepancy, it will result in a signature mismatch.

My bet is that the function signature is mismatched which is why this build would work fine for normal lua, but then fail for built wasm.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.