# graphql-needle

> Stitch your GraphQL schemas in a declarative way by using annotations

Latest version **0.0.10** (published 2017-10-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install graphql-needle
pnpm add graphql-needle
yarn add graphql-needle
bun add graphql-needle
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.10 |
| Published | 2017-10-16 |
| First published | 2017-10-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Alberto Mijares |
| Maintainers | almilo |
| Keywords | GraphQL, schema, schema language, stitch, annotations, directives, decorators, Apollo, JavaScript |

## Links

- npm: https://www.npmjs.com/package/graphql-needle
- Repository: https://github.com/almilo/graphql-needle
- Homepage: https://github.com/almilo/graphql-needle#readme
- Issues: https://github.com/almilo/graphql-needle/issues
- npm.io page: https://npm.io/package/graphql-needle

## Dependencies (3)

- [node-fetch](https://npm.io/package/node-fetch.md) 1.7.3
- [graphql-tools](https://npm.io/package/graphql-tools.md) 2.5.0
- [apollo-link-http](https://npm.io/package/apollo-link-http.md) 0.8.0

## Alternatives

- [apollo-link-http-common](https://npm.io/package/apollo-link-http-common.md) — 879.0K weekly downloads
- [react-relay](https://npm.io/package/react-relay.md) — 336.8K weekly downloads
- [relay-test-utils](https://npm.io/package/relay-test-utils.md) — 181.6K weekly downloads
- [@vendure/core](https://npm.io/package/@vendure/core.md) — 14.8K weekly downloads
- [@pnpm/deps.graph-sequencer](https://npm.io/package/@pnpm/deps.graph-sequencer.md) — 13.4K weekly downloads

## Recent versions

- 0.0.10 (latest) — 2017-10-16
- 0.0.9 — 2017-10-16
- 0.0.8 — 2017-10-16
- 0.0.7 — 2017-10-16
- 0.0.6 — 2017-10-16
- 0.0.5 — 2017-10-16
- 0.0.4 — 2017-10-16
- 0.0.3 — 2017-10-15
- 0.0.2 — 2017-10-15
- 0.0.1 — 2017-10-15
- 0.0.0 — 2017-10-15

## README

# graphql-needle
Stitch your GraphQL schemas in a declarative way by using annotations (aka directives).

[See Apollo schema stitching documentation](http://dev.apollodata.com/tools/graphql-tools/schema-stitching.html)

## Example

Instead of generating a stitched schema like so:

```js
import fetch from 'node-fetch';
import { HttpLink } from 'apollo-link-http';
import { introspectSchema, makeRemoteExecutableSchema, mergeSchemas } from 'graphql-tools';

const authorLink = new HttpLink({ uri: 'https://8xz15vx5q.lp.gql.zone/graphql', fetch });
const authorSchema = await introspectSchema(authorLink);
const authorExecutableSchema = makeRemoteExecutableSchema({ schema: authorSchema, link: authorLink });

const chirpLink = new HttpLink({ uri: 'https://vpzl4vxr3.lp.gql.zone/graphql', fetch });
const chirpSchema = await introspectSchema(chirpLink);
const chirpExecutableSchema = makeRemoteExecutableSchema({ schema: chirpSchema, link: chirpLink });

const linkTypeDefs = `
  extend type User {
    chirps: [Chirp]
  }
  extend type Chirp {
    author: User
  }
`;

const executableSchema = mergeSchemas({
  schemas: [authorExecutableSchema, chirpExecutableSchema, linkTypeDefs],
  resolvers: mergeInfo => ({
    User: {
      chirps: {
        fragment: `fragment UserFragment on User { id }`,
        resolve(parent, args, context, info) {
          const authorId = parent.id;
          return mergeInfo.delegate(
            'query',
            'chirpsByAuthorId',
            {
              authorId,
            },
            context,
            info,
          );
        },
      },
    },
    Chirp: {
      author: {
        fragment: `fragment ChirpFragment on Chirp { authorId }`,
        resolve(parent, args, context, info) {
          const id = parent.authorId;
          return mergeInfo.delegate(
            'query',
            'userById',
            {
              id,
            },
            context,
            info,
          );
        },
      },
    },
  }),
});
```

You can do it like so:

```js
import { makeAnnotatedExecutableSchema } from 'graphql-needle';

const authorSchemaUri = 'https://8xz15vx5q.lp.gql.zone/graphql'; // Apollo Launchpad https://launchpad.graphql.com/vpzl4vxr3
const chirpSchemaUri = 'https://vpzl4vxr3.lp.gql.zone/graphql'; // Apollo Launchpad https://launchpad.graphql.com/8xz15vx5q
const annotatedSchema = `
    extend type User @schema(uri: "${authorSchemaUri}") {
      chirps: [Chirp] @stitch(keyField: "id", queryField: "chirpsByAuthorId", queryParameter: "authorId")
    }
    extend type Chirp @schema(uri: "${chirpSchemaUri}") {
      author: User @stitch(keyField: "authorId", queryField: "userById", queryParameter: "id")
    }
`;


const executableSchema = await makeAnnotatedExecutableSchema(annotatedSchema);
```

[See running example](https://github.com/almilo/graphql-needle/blob/master/src/test/annotatedSchema.test.js)

---
_Source: https://npm.io/package/graphql-needle · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
