8.0.2 • Published 1 month ago

@graphql-tools/url-loader v8.0.2

Weekly downloads
1,258,694
License
MIT
Repository
github
Last release
1 month ago

toolskit

npm version CI Discord Chat

This package provides a few useful ways to create a GraphQL schema:

  1. Use the GraphQL schema language to generate a schema with full support for resolvers, interfaces, unions, and custom scalars. The schema produced is completely compatible with GraphQL.js.
  2. Mock your GraphQL API with fine-grained per-type mocking
  3. Automatically stitch multiple schemas together into one larger API

Documentation

Read the docs.

Binding to HTTP

If you want to bind your JavaScript GraphQL schema to an HTTP server, you can use express-graphql.

You can develop your Javascript based GraphQL API with graphql-tools and express-graphql together: One to write the schema and resolver code, and the other to connect it to a web server.

Example

When using graphql-tools, you describe the schema as a GraphQL type language string:

const typeDefs = `
type Author {
  id: ID! # the ! means that every author object _must_ have an id
  firstName: String
  lastName: String
  """
  the list of Posts by this author
  """
  posts: [Post]
}

type Post {
  id: ID!
  title: String
  author: Author
  votes: Int
}

# the schema allows the following query:
type Query {
  posts: [Post]
}

# this schema allows the following mutation:
type Mutation {
  upvotePost (
    postId: ID!
  ): Post
}

# we need to tell the server which types represent the root query
# and root mutation types. We call them RootQuery and RootMutation by convention.
schema {
  query: Query
  mutation: Mutation
}
`;

export default typeDefs;

Then you define resolvers as a nested object that maps type and field names to resolver functions:

const resolvers = {
  Query: {
    posts() {
      return posts;
    },
  },
  Mutation: {
    upvotePost(_, { postId }) {
      const post = find(posts, { id: postId });
      if (!post) {
        throw new Error(`Couldn't find post with id ${postId}`);
      }
      post.votes += 1;
      return post;
    },
  },
  Author: {
    posts(author) {
      return filter(posts, { authorId: author.id });
    },
  },
  Post: {
    author(post) {
      return find(authors, { id: post.authorId });
    },
  },
};

export default resolvers;

At the end, the schema and resolvers are combined using makeExecutableSchema:

import { makeExecutableSchema } from 'graphql-tools';

const executableSchema = makeExecutableSchema({
  typeDefs,
  resolvers,
});

This example has the entire type definition in one string and all resolvers in one file, but you can combine types and resolvers from multiple files and objects, as documented in the modularizing type definitions and merging resolvers section of the docs.

Contributions

Contributions, issues and feature requests are very welcome. If you are using this package and fixed a bug for yourself, please consider submitting a PR!

Maintainers

8.0.2

1 month ago

8.0.1

4 months ago

8.0.0

10 months ago

7.17.18

12 months ago

7.17.16

12 months ago

7.17.17

12 months ago

7.17.15

12 months ago

7.17.14

1 year ago

7.17.13

1 year ago

7.17.7

1 year ago

7.17.8

1 year ago

7.17.5

1 year ago

7.17.6

1 year ago

7.17.9

1 year ago

7.17.12

1 year ago

7.17.10

1 year ago

7.17.11

1 year ago

7.17.4

1 year ago

7.17.3

1 year ago

7.17.2

1 year ago

7.17.0

1 year ago

7.17.1

1 year ago

7.16.28

1 year ago

7.16.29

1 year ago

7.16.26

1 year ago

7.16.27

1 year ago

7.16.24

1 year ago

7.16.25

1 year ago

7.16.22

1 year ago

7.16.23

1 year ago

7.16.20

1 year ago

7.16.21

1 year ago

7.16.19

1 year ago

7.16.17

1 year ago

7.16.18

1 year ago

7.16.15

1 year ago

7.16.16

1 year ago

7.16.13

1 year ago

7.16.14

1 year ago

7.16.11

1 year ago

7.16.12

1 year ago

7.16.8

1 year ago

7.16.9

1 year ago

7.16.7

1 year ago

7.16.10

1 year ago

7.16.6

1 year ago

7.16.5

1 year ago

7.16.4

1 year ago

7.16.3

1 year ago

7.15.0

2 years ago

7.16.2

2 years ago

7.14.2

2 years ago

7.14.3

2 years ago

7.14.0

2 years ago

7.14.1

2 years ago

7.16.0

2 years ago

7.16.1

2 years ago

7.11.0

2 years ago

7.9.25

2 years ago

7.13.3

2 years ago

7.13.4

2 years ago

7.13.1

2 years ago

7.13.2

2 years ago

7.13.0

2 years ago

7.13.9

2 years ago

7.13.7

2 years ago

7.13.8

2 years ago

7.13.5

2 years ago

7.13.6

2 years ago

7.10.0

2 years ago

7.12.4

2 years ago

7.12.2

2 years ago

7.12.3

2 years ago

7.12.0

2 years ago

7.12.1

2 years ago

7.9.24

2 years ago

7.9.17

2 years ago

7.9.18

2 years ago

7.9.19

2 years ago

7.9.20

2 years ago

7.9.21

2 years ago

7.9.22

2 years ago

7.9.23

2 years ago

7.9.16

2 years ago

7.9.10

2 years ago

7.9.13

2 years ago

7.9.14

2 years ago

7.9.11

2 years ago

7.9.12

2 years ago

7.9.15

2 years ago

7.9.9

2 years ago

7.8.0

2 years ago

7.9.3

2 years ago

7.9.2

2 years ago

7.9.1

2 years ago

7.9.0

2 years ago

7.9.7

2 years ago

7.9.6

2 years ago

7.9.5

2 years ago

7.9.4

2 years ago

7.9.8

2 years ago

7.7.1

2 years ago

7.7.2

2 years ago

7.6.0

2 years ago

7.7.0

2 years ago

7.5.3

2 years ago

7.5.2

2 years ago

7.5.1

2 years ago

7.5.0

2 years ago

7.4.2

2 years ago

7.4.1

2 years ago

7.4.0

2 years ago

7.2.1

2 years ago

7.3.0

2 years ago

7.2.0

3 years ago

7.1.0

3 years ago

7.0.12

3 years ago

7.0.11

3 years ago

7.0.10

3 years ago

7.0.9

3 years ago

7.0.8

3 years ago

7.0.7

3 years ago

7.0.6

3 years ago

7.0.5

3 years ago

7.0.4

3 years ago

7.0.0

3 years ago

7.0.3

3 years ago

7.0.2

3 years ago

7.0.1

3 years ago

6.8.3

3 years ago

6.9.0

3 years ago

6.10.1

3 years ago

6.10.0

3 years ago

6.8.2

3 years ago

6.8.1

3 years ago

6.8.0

3 years ago

6.7.1

3 years ago

6.7.0

3 years ago

6.6.0

3 years ago

6.5.0

3 years ago

6.4.0

3 years ago

6.3.2

3 years ago

6.3.1

3 years ago

6.3.0

3 years ago

6.2.4

3 years ago

6.2.3

4 years ago

6.2.2

4 years ago

6.2.1

4 years ago

6.2.0

4 years ago

6.1.0

4 years ago

6.0.18

4 years ago

6.0.17

4 years ago

6.0.16

4 years ago

6.0.15

4 years ago

6.0.14

4 years ago

6.0.13

4 years ago

6.0.12

4 years ago

6.0.11

4 years ago

6.0.10

4 years ago

6.0.9

4 years ago

6.0.8

4 years ago

6.0.7

4 years ago

6.0.6

4 years ago

6.0.5

4 years ago

6.0.4

4 years ago

6.0.3

4 years ago

6.0.2

4 years ago

6.0.1

4 years ago

6.0.0

4 years ago

6.0.0-alpha.2

4 years ago

6.0.0-alpha.1

4 years ago