From d0b24a2381a10f4988594244a6d630f4d676ae3f Mon Sep 17 00:00:00 2001 From: Jesse Rosenberger Date: Fri, 20 Apr 2018 17:29:11 +0300 Subject: [PATCH] Follow-up on previous commit. --- docs/_config.yml | 12 ++-- docs/source/essentials/fetching-data.md | 5 ++ docs/source/essentials/queries.md | 77 ------------------------- 3 files changed, 10 insertions(+), 84 deletions(-) create mode 100644 docs/source/essentials/fetching-data.md delete mode 100644 docs/source/essentials/queries.md diff --git a/docs/_config.yml b/docs/_config.yml index 8ae76904..1cb00d69 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -12,20 +12,16 @@ sidebar_categories: - whats-new Essentials: - essentials/building-schema - - essentials/queries - - essentials/mutations + - essentials/running-a-server + - essentials/fetching-data Schema Development: - schemas/organization - schemas/types - schemas/directives - schemas/resolvers - schemas/context - Running a Server: - - server/index - - server/middleware - - server/queries + TODO: - server/engine - - server/secrets Best Practices: - best-practices/authentication - best-practices/permissions @@ -38,6 +34,8 @@ sidebar_categories: - best-practices/versioning - best-practices/schema-stitching - best-practices/infrastructure + - best-practices/testing + - best-practices/secrets Working with Backends: - backends/general - backends/sql diff --git a/docs/source/essentials/fetching-data.md b/docs/source/essentials/fetching-data.md new file mode 100644 index 00000000..a7abdc26 --- /dev/null +++ b/docs/source/essentials/fetching-data.md @@ -0,0 +1,5 @@ +--- +title: Fetching Data +--- + +## Fetching Data \ No newline at end of file diff --git a/docs/source/essentials/queries.md b/docs/source/essentials/queries.md deleted file mode 100644 index 0d45382f..00000000 --- a/docs/source/essentials/queries.md +++ /dev/null @@ -1,77 +0,0 @@ ---- -title: Queries ---- - -## Prerequisites - -* A basic understanding of a GraphQL schema ([Schema]()) -## Prerequisites - -## Overview - -A GraphQL query is for reading data. The schema defines the types of queries which are available to the clients connecting to your server. - -## Material - -* GraphQL query defines the shape of data that will be returned by a particular request - * This is what an author + books query looks like coming from the client - * make sure it has arguments -* This query is then checked again the server's schema - * looks like this: -* "root" level queries define the main entry points -* Each of those root queries returns a type -* You have to have a query -* It's an entry point like all rest endpoints -* It's how you fetch data - -**Actually writing resolvers for your queries is found in server/queries** - -> TODO: The below headings were left over from the other document. Do we want to remove them? - -## Implementing Queries in Apollo Server - -> (Evans) this section feels very similar to resolvers - -Now that we understand the Query type, GraphQL types, and resolvers, we can explain the following code to define our schema and resolvers. This example shows the - -```js -const { ApolloServer } = require('apollo-server'); - -const typeDefs = ` - type Process { - params: [String] - program: String - } - - type Query { - process: Process - argv: [String] - } -`; - -// Resolvers define the technique for fetching the types in the -// schema. We'll retrieve books from the "books" array above. -const resolvers = { - Process: { - params: (parent) => parent.argv.slice(1) - program: (parent) => parent.argv[0] - url: (_,_,context) => context.req.baseUrl - } - - Query: { - process: () => process - argv: () => process.argv - }, -}; - -new ApolloServer({ typeDefs, resolvers, context: { req } }) - .listen() - .then(({ url }) => { - console.log(`Visit ${url} to run queries!`); - }); -``` - -## Material to include - -* This section ties all of the information in the prereqs to show you how to implement Queries with the Apollo Server - * essentially copy and paste code that you can then add onto