Skip to content

Commit

Permalink
Merge branch 'staging' into check-every-subscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
imolorhe committed Aug 8, 2020
2 parents 9d3f41f + a3c8b62 commit 08416a9
Show file tree
Hide file tree
Showing 10 changed files with 1,063 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -106,6 +106,10 @@ You can use altair with an express server using [altair-express-middleware](http
### Usage with koa
You can use altair with a koa server using [altair-koa-middleware](https://www.npmjs.com/package/altair-koa-middleware). Read more about how to use this [here](https://altair.sirmuel.design/docs/integrations/altair-koa-middleware).

### Usage with Fastify

You can use altair with a Fastify server using [altair-fastify-plugin](https://www.npmjs.com/package/altair-fastify-plugin). Read more about how to use this [here](packages/altair-fastify-plugin/README.md).

### Usage with Laravel (PHP)
You can use altair in a Laravel project using [xkojimedia/laravel-altair-graphql](https://packagist.org/packages/xkojimedia/laravel-altair-graphql):

Expand Down
6 changes: 3 additions & 3 deletions packages/altair-app/yarn.lock
Expand Up @@ -4900,9 +4900,9 @@ electron@*:
extract-zip "^1.0.3"

elliptic@^6.0.0, elliptic@^6.5.2:
version "6.5.2"
resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.5.2.tgz#05c5678d7173c049d8ca433552224a495d0e3762"
integrity sha512-f4x70okzZbIQl/NSRLkI/+tteV/9WqL98zx+SQ69KbXxmVrmjwsNUPn/gYJJ0sHvEak24cZgHIPegRePAtA/xw==
version "6.5.3"
resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.5.3.tgz#cb59eb2efdaf73a0bd78ccd7015a62ad6e0f93d6"
integrity sha512-IMqzv5wNQf+E6aHeIqATs0tOLeOTwj1QKbRcS3jBbYkl5oLAserA8yJTT7/VyHUYG91PRmPyeQDObKLPpeS4dw==
dependencies:
bn.js "^4.4.0"
brorand "^1.0.1"
Expand Down
3 changes: 3 additions & 0 deletions packages/altair-fastify-plugin/.prettierrc
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
40 changes: 40 additions & 0 deletions packages/altair-fastify-plugin/README.md
@@ -0,0 +1,40 @@
# altair-fastify-plugin

[![npm](https://img.shields.io/npm/v/altair-fastify-plugin.svg)](https://www.npmjs.com/package/altair-fastify-plugin)

This is a [**Fastify Plugin**](https://www.fastify.io/docs/master/Plugins/) for hosting an instance of **Altair GraphQL Client**, with support for **TypeScript**, and tested for **Fastify v3**.

## Install

```sh
npm install altair-fastify-plugin
# or
yarn add altair-fastify-plugin
```

## Usage

```js
// const Fastify = require("fastify");
import Fastify from 'fastify';
// const AltairFastify = require("altair-fastify-plugin");
import AltairFastify from 'altair-fastify-plugin';

const app = Fastify();

// ...

app.register(AltairFastify, {
/**
* All these are the defaults.
*/
path: '/altair',
baseURL: '/altair/',
endpointURL: '/graphql',
});

// ...

// Altair available at localhost:3000/altair
app.listen(3000);
```
51 changes: 51 additions & 0 deletions packages/altair-fastify-plugin/example/fastifyGQL.js
@@ -0,0 +1,51 @@
const Fastify = require('fastify');
const GQL = require('fastify-gql');
// const AltairFastify = require("altair-fastify-plugin");
const AltairFastify = require('../');

const app = Fastify();

const schema = `
type Query {
add(x: Int, y: Int): Int
}
`;

const resolvers = {
Query: {
add: async (_, { x, y }) => x + y,
},
};

app.register(GQL, {
schema,
resolvers,
graphiql: false,
ide: false,
path: '/graphql',
});

app.register(AltairFastify, {
/**
* All these are the defaults.
*/
path: '/altair',
baseURL: '/altair/',
endpointURL: '/graphql',

/**
* Check all the options Altair has
*/
initialQuery: `
query {
add(x: 1, y: 2)
}
`,
});

app.get('/', async function (req, reply) {
const query = '{ add(x: 2, y: 2) }';
return reply.graphql(query);
});

app.listen(3000);
50 changes: 50 additions & 0 deletions packages/altair-fastify-plugin/example/fastifyGQL.ts
@@ -0,0 +1,50 @@
import Fastify from 'fastify';
import GQL from 'fastify-gql';
// import AltairFastify from "altair-fastify-plugin";
import AltairFastify from '../';

const app = Fastify({
logger: {
level: 'info',
},
});

const schema = `
type Query {
add(x: Int, y: Int): Int
}
`;

const resolvers = {
Query: {
add: async (_: unknown, { x, y }: { x: number; y: number }) => x + y,
},
};

app.register(GQL, {
schema,
resolvers,
graphiql: false,
ide: false,
path: '/graphql',
});

app.register(AltairFastify, {
/**
* All these are the defaults.
*/
path: '/altair',
baseURL: '/altair/',
endpointURL: '/graphql',

/**
* Check all the options Altair has
*/
initialQuery: `
query {
add(x: 1, y: 2)
}
`,
});

app.listen(3000);
47 changes: 47 additions & 0 deletions packages/altair-fastify-plugin/package.json
@@ -0,0 +1,47 @@
{
"name": "altair-fastify-plugin",
"version": "2.4.10",
"description": "Fastify Plugin of Altair GraphQL Client",
"keywords": [
"graphql",
"fastify",
"altair",
"client",
"gql"
],
"homepage": "https://github.com/imolorhe/altair#readme",
"bugs": {
"url": "https://github.com/imolorhe/altair/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/imolorhe/altair.git"
},
"license": "MIT",
"author": "PabloSz <pablosaez1995@gmail.com>",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist",
"example"
],
"scripts": {
"example": "ts-node example/fastifyGQL.ts",
"prepare": "tsc",
"test": "echo \"Error: no test specified\" && exit 0"
},
"dependencies": {
"altair-static": "^2.4.11",
"fastify-plugin": "^2.0.1",
"fastify-static": "^3.2.0"
},
"devDependencies": {
"fastify": "^3.1.1",
"fastify-gql": "^5.1.1",
"ts-node": "^8.10.2",
"typescript": "^3.9.7"
},
"peerDependencies": {
"fastify": "^3.1.1"
}
}
55 changes: 55 additions & 0 deletions packages/altair-fastify-plugin/src/index.ts
@@ -0,0 +1,55 @@
import { getDistDirectory, renderAltair, RenderOptions } from 'altair-static';
import fp from 'fastify-plugin';
import fastifyStatic from 'fastify-static';

import type { FastifyPluginCallback } from 'fastify';

export interface AltairFastifyPluginOptions extends RenderOptions {
/**
* URL to set as the server endpoint.
*
* By default is `/graphql`
*/
endpointURL?: string;
/**
* URL to be used as a base for relative URLs and hosting needed static files.
*
* By default is `/altair/`
*/
baseURL?: string;
/**
* Path in which Altair will be accesible.
*
* By default is `/altair`
*/
path?: string;
}

const fastifyAltairPlugin: FastifyPluginCallback<AltairFastifyPluginOptions> = (
fastify,
{
path = '/altair',
baseURL = '/altair/',
endpointURL = '/graphql',
...renderOptions
} = {},
done
) => {
fastify.register(fastifyStatic, {
root: getDistDirectory(),
prefix: baseURL,
});

const altairPage = renderAltair({ baseURL, endpointURL, ...renderOptions });

fastify.get(path, (_req, res) => {
res.type('text/html').send(altairPage);
});

done();
};

export default fp(fastifyAltairPlugin, {
fastify: '>= 3.x',
name: 'altair-fastify-plugin',
});
73 changes: 73 additions & 0 deletions packages/altair-fastify-plugin/tsconfig.json
@@ -0,0 +1,73 @@
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */

/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es2018" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
"lib": [
"es2018"
] /* Specify library files to be included in the compilation. */,
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
"declaration": true /* Generates corresponding '.d.ts' file. */,
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./dist" /* Redirect output structure to the directory. */,
// "rootDir": "./" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */

/* Strict Type-Checking Options */
"strict": true /* Enable all strict type-checking options. */,
"noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */,
"strictNullChecks": true /* Enable strict null checks. */,
"strictFunctionTypes": true /* Enable strict checking of function types. */,
"strictBindCallApply": true /* Enable strict 'bind', 'call', and 'apply' methods on functions. */,
"strictPropertyInitialization": true /* Enable strict checking of property initialization in classes. */,
"noImplicitThis": true /* Raise error on 'this' expressions with an implied 'any' type. */,
"alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */,

/* Additional Checks */
"noUnusedLocals": true /* Report errors on unused locals. */,
"noUnusedParameters": true /* Report errors on unused parameters. */,
"noImplicitReturns": true /* Report error when not all code paths in function return a value. */,
"noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */,

/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */

/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */

/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */

/* Advanced Options */
"skipLibCheck": true /* Skip type checking of declaration files. */,
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
}

0 comments on commit 08416a9

Please sign in to comment.