Skip to content

Commit

Permalink
modularium phase 1
Browse files Browse the repository at this point in the history
  • Loading branch information
aexol committed Jul 26, 2024
1 parent c157549 commit 2143cfd
Show file tree
Hide file tree
Showing 58 changed files with 751 additions and 1,760 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"cSpell.words": [
"aexol",
"axolotl",
"modularium",
"Supergraph"
],
"typescript.tsdk": "node_modules/typescript/lib",
Expand Down
107 changes: 1 addition & 106 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ This is super alpha version of universal backend( or frontend if you want to cre
Writing GraphQL for backend developers is still complicated when you want to go schema-first instead of code-first. Moreover I felt like we need an **evolutionary** framework.

For example using `apollo-server` but want to switch to `graphql-yoga` ? No problem just change an adapter.

Want to experiment with `stucco-js` with Go lang core? No problem change the adapter.

Want to set up every part of your system in different graphql server with microservices?. No problem.

## 😮 What?
Expand All @@ -24,87 +21,13 @@ Axolotl is a framework overlord/wrapper to forget about type-casting and looking
- 😂 easy to setup,start and integrate
- 🫡 from GraphQL Editor and Aexol teams
- 🪦 No RIP we will maintain forever
- 🐙 Micro federation!
- 🦕 Deno support from 0.2.7

## 🫠 How?

Axolotl provides type-safety and it is up to you to choose an adapter (or write your own). And develop your GraphQL thing super-fast. How it runs it depends what framework you choose under the hood.

### With stucco

```sh
npm i @aexol/axolotl-core @aexol/axolotl-graphql-yoga
```

Now you need a `schema.graphql` file or a URL with settings to download the schema from upstream. Out of it Axolotl can generate simple type definitions needed for the library out of your GraphQL Schema.

`models.js` are located where you specify when initiating Axolotl

First execute init command

```sh
npx @aexol/axolotl init
```

Then write your index.ts file.

```ts
import { FieldResolveInput } from 'stucco-js';
import { Axolotl } from '@aexol/axolotl-core';
import { stuccoAdapter } from '@aexol/axolotl-stucco';
import { Models } from '@/src/models.js';
import { BeerOrm } from '@/src/ormBeersFile.js';

// choose your adapter
const { applyMiddleware, createResolvers } = Axolotl(stuccoAdapter)<Models>();

const Beer = BeerOrm();

const resolvers = createResolvers({
Query: {
beers: () => Beer.list(),
},
Mutation: {
addBeer: (input, args) => {
return Beer.create(args.beer);
},
deleteBeer: (input, args) => {
return Beer.remove(args);
},
updateBeer: (input, args) => {
return Beer.update(args._id, args.beer);
},
},
});
// scroll down for the second part of the file
```
And choose an adapter. Base idea is that code should run with every GraphQL Server available in nodejs.

### I choose graphql-yoga
```ts
//This you should add on the top

// And change the Axolotl import to yoga specific

const { applyMiddleware, createResolvers } = Axolotl(graphqlYogaAdapter)<Models>();

// This is yoga specific
applyMiddleware(
resolvers,
[
(input) => {
console.log('Hello from Middleware I run only on Query.beers');
return input;
},
],
{ Query: { beers: true } },
);

graphqlYogaadapter({resolvers}).server.listen(4000, () => {
console.log('LISTENING');
});
```

## 🧌 Who?

Me [aexol](https://github.com/aexol) is the author of the lib. I was in the type-safety rabbit hole while building [GraphQL Zeus](https://github.com/graphql-editor/graphql-zeus) a GraphQL Client downloaded almost Million of times. While maintaining zeus and developing together with all-the-time changing TypeScript is really hard. I discovered - I can write something simpler - much powerful, that community needs, that integrates with everything - using the same knowledge.
Expand All @@ -124,34 +47,6 @@ Packages to support super fast local development
### Micro Federation
You can use micro federation feature in axolotl. Micro federation means all the modules are located within one project or one monorepo or are distributed as npm packages. Those axolotl projects are merged to the supergraph later.

To use micro federation you need to create config for your project containing this kind of content:
```json
{
"schema": "schema.graphql",
"models": "src/models.ts",
"federation":[
{
"schema":"src/beers/schema.graphql",
"models":"src/beers/models.ts",
},
{
"schema":"src/shop/schema.graphql",
"models":"src/shop/models.ts",
}
]
}
```




### To do
- [x] try to implement graphql-yoga adapter as a presentation that listen based frameworks can work with axolotl too
- [x] write documentation
- [ ] implement e2e testing functionality that takes, query, headers, result and runs the test
- [x] create command to use npx @aexol/axolotl https://github.com/facebook/create-react-app/blob/main/packages/create-react-app/createReactApp.js here is the good example
- [ ] add schema generation to ts file from URL

## Development

To start developing you need to know few things:
Expand Down
4 changes: 2 additions & 2 deletions adapters/apollo-server/package-lock.json

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

4 changes: 2 additions & 2 deletions adapters/apollo-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aexol/axolotl-apollo-server",
"version": "0.3.8",
"version": "0.3.9",
"private": false,
"main": "./lib/index.js",
"author": "Aexol, Artur Czemiel",
Expand All @@ -14,7 +14,7 @@
"lib"
],
"dependencies": {
"@aexol/axolotl-core": "^0.3.8",
"@aexol/axolotl-core": "^0.3.9",
"@apollo/server": "^4.9.4",
"@graphql-tools/schema": "^9.0.19",
"@graphql-tools/utils": "^9.2.1"
Expand Down
4 changes: 2 additions & 2 deletions adapters/graphql-yoga/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aexol/axolotl-graphql-yoga",
"version": "0.3.8",
"version": "0.3.9",
"private": false,
"main": "./lib/index.js",
"author": "Aexol, Artur Czemiel",
Expand All @@ -14,7 +14,7 @@
"lib"
],
"dependencies": {
"@aexol/axolotl-core": "^0.3.8",
"@aexol/axolotl-core": "^0.3.9",
"@graphql-tools/utils": "^10.3.2",
"graphql-yoga": "^4.0.5"
},
Expand Down
4 changes: 2 additions & 2 deletions adapters/stucco/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aexol/axolotl-stucco",
"version": "0.3.8",
"version": "0.3.9",
"private": false,
"main": "./lib/index.js",
"author": "Aexol, Artur Czemiel",
Expand All @@ -14,7 +14,7 @@
"lib"
],
"dependencies": {
"@aexol/axolotl-core": "^0.3.8",
"@aexol/axolotl-core": "^0.3.9",
"stucco-js": "^0.10.19"
}
}
10 changes: 5 additions & 5 deletions docs/pages/_meta.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"index": "Axolotl",
"getting-started": "Getting Started",
"from-examples": "Start from Starter",
"config": "Configuration",
"resolvers": "Resolvers",
"directives": "Directives",
"from-examples": "Start from Starter",
"micro-federation": "Micro federation",
"inspect": "Inspect missing resolvers",
"infer-source": "Infer Source",
"adapters": "Adapters",
"inspect": "Inspect missing resolvers",
"config": "Configuration",
"micro-federation": "Micro federation",
"tests": "Tests",
"deploy": "Deploy",
"development": "Development",
"tests": "Tests",
"roadmap": "Roadmap"
}
1 change: 0 additions & 1 deletion docs/pages/adapters.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ parts of your graph in future.
- [GraphQL Yoga NodeJS](/adapters/graphql-yoga)
- [GraphQL Yoga Deno](/adapters/deno-yoga)
- [Apollo Server](/adapters/apollo-server)
- [StuccoJS](/adapters/stucco)


## How to write our own adapter
Expand Down
4 changes: 2 additions & 2 deletions docs/pages/adapters/apollo-server.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ Now you need a `schema.graphql` file or a URL with settings to download the sche

`models.ts` are located where you specify when initiating Axolotl

First execut emodels command
First execute axolotl `build` command

```sh
npx @aexol/axolotl models
npx @aexol/axolotl build
```

Then write your `index.ts` file. The `apolloServerAdapter()` will return ApolloServer object, so to start a server in easiest way you may use standalone server from apollo.
Expand Down
4 changes: 2 additions & 2 deletions docs/pages/adapters/graphql-yoga.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ Now you need a `schema.graphql` file or a URL with settings to download the sche

`models.ts` are located where you specify when initiating Axolotl

First execute models command
First execute `axolotl build` command

```sh
npx @aexol/axolotl models
npx @aexol/axolotl build
```

Then write your `axolotl.ts` file.
Expand Down
27 changes: 25 additions & 2 deletions docs/pages/config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,38 @@ axolotl models

The arguments -m and -s are mandatory. If they are not provided as arguments, you can input them via standard input.

Based on the [beerpub-yoga example](/examples/beerpub-yoga) run `axolotl models`:
Based on the [beerpub-yoga example](/examples/beerpub-yoga) run `axolotl build`:

Axolotl will generate a configuration file named "configuration.json" which will contain the flags passed when building the models, an example configuration file may look like this

```json
```json filename="axolotl.json"
{
"schema": "schema.graphql",
"models": "src/models.ts"
}
```

This guide should help you understand your Axolotl configuration. More detailed examples can be found in the Examples section.

## Micro federation

Config supports GraphQL Federation baked into axolotl. The main schema file is
generated then and becomes `supergraph`. The example how federation works in
Axolotl is used in [beerpub-yoga-federated example](/examples/beerpub-yoga-federated)

```json filename="axolotl.json"
{
"schema": "schema.graphql",
"models": "src/models.ts",
"federation":[
{
"schema":"src/beers/schema.graphql",
"models":"src/beers/models.ts"
},
{
"schema":"src/shop/schema.graphql",
"models":"src/shop/models.ts"
}
]
}
```
6 changes: 3 additions & 3 deletions docs/pages/development.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ npm run build --ws --if-present
```
- to run an example execute:
```sh
npm run start -w beerpub
npm run start -w examples/beerpub-yoga
```

## Repository
Expand All @@ -25,5 +25,5 @@ Just wrap your adapter in AxolotlAdapter function which receives resolvers witho
### Examples
Place to experiments with axolotl and its packages

### Federation 🔨 WIP
Packages to support integration between different schemas. It means that it should be easy set up multiple schemas and runtime for one backend
### Modularium
CLI and modules to support micro-federation inside axolotl framework
11 changes: 6 additions & 5 deletions docs/pages/from-examples.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ We offer carefully crafted starter templates with all the necessary configuratio

| Prefix | Default directory | Documentation |
| ------------- | ----------------- | ---------------------------------------------------------- |
| create-stucco | beerpub | [stucco.js](https://github.com/graphql-editor/stucco-js) |
| create-yoga | beerpub-yoga | [Yoga GraphQL](https://github.com/dotansimha/graphql-yoga) |
| create-apollo-server | beerpub-apollo-server | [Apollo Server](https://github.com/apollographql/apollo-server) |
| create-deno-yoga | /deno/examples/beerpub-yoga | [Yoga GraphQL](https://github.com/dotansimha/graphql-yoga) [Deno][https://docs.deno.com] |

## 🛫 Installation
Expand All @@ -20,14 +20,15 @@ The `dir` argument is optional and represents the directory where the project wi
npx @aexol/axolotl [prefix] [dir]
```

⭐ CLI already installed?

If you have already installed the CLI, you can use the `axolotl` command.
For example

```sh
axolotl [prefix] [dir]
npx @aexol/axolotl create-yoga my-project
```

Will create the axolotl project using `graphql-yoga` engine inside `my-project`
directory - **simple**!

### 🦕 Deno
This is just a scaffold command but you can run it with deno to :D

Expand Down
Loading

0 comments on commit 2143cfd

Please sign in to comment.