npm package: @fleek-platform/graphql
Description: Fleek Graphql is the service unifying all graphql service into once.
Latest version: 2.26.3

# Fleek GraphQL

Fleek Graphql is the service unifying all graphql service into once.

## Details

Even though we are using Prisma, we write custom resolvers, mutations and queries. The examples of the mutations and queries are inside the [./src/resolvers](./src/resolvers/) directory and schema examples are located in [./src/schema](./src/schema/) directory.

### Adding a new functionality

Generally, this will be new functionality which will include creating a new schema. The schemas are based on the [Pothos](https://pothos-graphql.dev/docs/guide#create-a-simple-schema) which are then used to get the data. This is used to resolve the relations such as [`project`](./src/schema/PrivateGateway.ts#L14) or a [`zone`](./src/schema/PrivateGateway.ts#L18).

_Step One:_

Start by creating a file under `./src/schema` following `CamelCase.ts` naming convention. At this point check the other files in the directory and how they are done, some are more complex than others, pick one like [Domain Schema](./src/schema/Domain.ts) then copy/paste and adapt. Once you are done with adapting include a new file in the [`./src/schema.ts`](./src/schema.ts) as it is done with other files.

_Step Two:_

The next step is to create a directory for mutations and queries. Create a directory inside the [`./src/resolvers`](./src/resolvers) following the `camelCase` naming convention. Inside create `mutations` and `queries` directories. Each directory will contain an implementation file that `export default` the [`mutationField`](https://pothos-graphql.dev/docs/api/schema-builder#mutationtypeoptions-fields) with the correct mutation name written in `camelCase` and a callback function. Now it is time to create a test file. For the references check how other implementations are testing their mutations and queries. The tests are written
in a way that will cover as many as possible known cases.

Once you are done with adapting include a new file in the [`./src/schema.ts`](./src/schema.ts) as it is done with other files.

_Needed commands_

```bash
# generate the client code
pnpm generate

# build the package
pnpm build

# test it. requires docker
pnpm test

# to test only failed tests,
# edit the test:watch command ( do not commit ) with correct path then execute it
pnpm test:watch

# start the mysql docker container
pnpm prepare:test

# or all together
pnpm generate && pnpm build && pnpm test
```

### Stack

[NodeJS](https://nodejs.org) as a runtime environment.

- [GraphQL Yoga](https://the-guild.dev/graphql/yoga-server) as GraphQL Server implementation.
- [Prisma Auth](../../prisma/auth/) as Fleek Auth DB connector.
- [Pothos](https://pothos-graphql.dev) as the GraphQL type-safe Schema builder using [typescript](<(https://www.typescriptlang.org)>).
- [ESLint](https://eslint.org/) with [Prettier](https://prettier.io/) for linting.

#### TBD

- Logger

## Development

1. Install NodeJS from [the official website](https://nodejs.org) or using [nvm](https://github.com/creationix/nvm).
2. Install [pnpm](https://pnpm.io/installation) dependency manager.
3. Install dependencies usign `pnpm i` from root path.
4. Set environmental variables in a new `.env` file as desired.
5. `pnpm dev`, and happy coding!

## Testing

1. Install Node, pnpm and all dependencies for package as it is described above.
2. You need [Docker](https://www.docker.com/get-started/) to run container with Mysql server for integration testing.
3. Type `pnpm prepare:test` or set up Mysql container manually
4. Type `pnpm test` to run all unit & integration tests

## Contributing

1. Fork it
2. Create your feature branch: `git checkout -b my-new-feature`
3. Run the tests: `pnpm test`
4. Commit your changes: `git commit -am 'Add some feature'`
5. Push to the branch: `git push origin my-new-feature`
6. Create new Pull Request following the corresponding template guidelines