ebook img

Full Stack GraphQL Applications: With React, Node.js, and Neo4j PDF

265 Pages·2022·20.079 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Full Stack GraphQL Applications: With React, Node.js, and Neo4j

With React, Node.js, and Neo4j William Lyon M A N N I N G { moviesByTitle(title: "Matrix") { title year } } 4 Apollo GraphQL query Client 1 Request 3 GraphQL API Response Apollo { "data": { Server "moviesByTitle": [ { "title": "Matrix Web Reloaded, The", client } "year": 2003 2 MATCH R(EmT:UMRoNv ime. t{ittiltel,e :m ."yMeaatrrix"}) ] } Cypher } Bolt JavaScript driver 1 Client issues GraphQL query 2 GraphQL API sends Cypher query to Neo4j 3 Response sent to client Database 4 Data updated in React component props and view rendered A GraphQL request in a full stack GraphQL application Full Stack GraphQL Applications Full Stack GraphQL Applications W R , N . , N 4 ITH EACT ODE JS AND EO J WILLIAM LYON MANNING SHELTER ISLAND For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact Special Sales Department Manning Publications Co. 20 Baldwin Road PO Box 761 Shelter Island, NY 11964 Email: [email protected] ©2022 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine. The author and publisher have made every effort to ensure that the information in this book was correct at press time. The author and publisher do not assume and hereby disclaim any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from negligence, accident, or any other cause, or from any usage of the information herein. Manning Publications Co. Development editor: Karen Miller 20 Baldwin Road Technical development editor: Doug Warren PO Box 761 Review editor: Aleksandar Dragosavljević Shelter Island, NY 11964 Production editor: Andy Marinkovich Copy editor: Christian Berk Proofreader: Melody Dolab Technical proofreader: Niek Palm Typesetter: Gordan Salinovic Cover designer: Marija Tudor ISBN 9781617297038 Printed in the United States of America brief contents P 1 G G QL....................1 ART ETTING STARTED WITH FULL STACK RAPH 1 ■ What is full stack GraphQL? 3 2 ■ Graph thinking with GraphQL 29 3 ■ Graphs in the database 49 4 ■ The Neo4j GraphQL Library 67 P 2 B ................................................99 ART UILDING THE FRONTEND 5 ■ Building user interfaces with React 101 6 ■ Client-side GraphQL with React and Apollo Client 116 P 3 F .........................................137 ART ULL STACK CONSIDERATIONS 7 ■ Adding authorization and authentication 139 8 ■ Deploying our full stack GraphQL application 172 9 ■ Advanced GraphQL considerations 212 v contents preface xi acknowledgments xii about this book xiii about the author xvi about the cover illustration xvii P 1 G G QL ......... 1 ART ETTING STARTED WITH FULL STACK RAPH 1 What is full stack GraphQL? 3 1.1 A look at full stack GraphQL 3 1.2 GraphQL 5 GraphQL type definitions 5 ■ Querying with GraphQL 7 Advantages of GraphQL 10 ■ Disadvantages of GraphQL 12 GraphQL tooling 13 1.3 React 15 React components 16 ■ JSX 16 ■ React tooling 16 1.4 Apollo 18 Apollo Server 18 ■ Apollo Client 18 1.5 Neo4j Database 18 Property graph data model 19 ■ Cypher query language 19 Neo4j tooling 20 vi CONTENTS vii 1.6 How it all fits together 23 React and Apollo Client: Making the request 24 ■ Apollo Server and GraphQL backend 25 ■ React and Apollo Client: Handling the response 26 1.7 What we will build in this book 27 1.8 Exercises 28 2 Graph thinking with GraphQL 29 2.1 Your application data is a graph 30 2.2 Graphs in GraphQL 31 API modeling with type definitions: GraphQL-first development 31 Resolving data with resolvers 37 ■ Our first resolver 38 2.3 Combining type definitions and resolvers with Apollo Server 41 Using Apollo Server 41 ■ Apollo Studio 42 ■ Implementing resolvers 43 ■ Querying using Apollo Studio 46 2.4 Exercises 47 3 Graphs in the database 49 3.1 Neo4j overview 50 3.2 Graph data modeling with Neo4j 50 The property graph model 51 ■ Database constraints and indexes 54 3.3 Data modeling considerations 54 Node vs. property 54 ■ Node vs. relationship 55 ■ Indexes 55 Specificity of relationship types 55 ■ Choosing a relationship direction 55 3.4 Tooling: Neo4j desktop 55 3.5 Tooling: Neo4j Browser 56 3.6 Cypher 57 Pattern matching 57 ■ Properties 58 ■ CREATE 58 MERGE 62 ■ Defining database constraints with cypher 63 MATCH 64 ■ Aggregations 65 3.7 Using the Neo4j client drivers 65 3.8 Exercises 66 viii CONTENTS 4 The Neo4j GraphQL Library 67 4.1 Common GraphQL problems 68 Poor performance and the n + 1 query problem 68 ■ Boilerplate and developer productivity 69 4.2 Introducing GraphQL database integrations 69 4.3 The Neo4j GraphQL Library 69 Project setup 70 ■ Generated GraphQL schema from type definitions 74 4.4 Basic GraphQL queries 76 4.5 Ordering and pagination 79 4.6 Nested queries 80 4.7 Filtering 82 where argument 82 ■ Nested filter 82 ■ Logical operators: AND, OR 83 ■ Filtering in selections 85 4.8 Working with temporal fields 86 Using a Date type in queries 86 ■ Date and DateTime filters 87 4.9 Working with spatial data 88 The Point type in selections 88 ■ Distance filter 89 4.10 Adding custom logic to our GraphQL API 90 The @cypher GraphQL schema directive 90 ■ Implementing custom resolvers 94 4.11 Introspecting GraphQL schema from an existing database 96 4.12 Exercises 97 P 2 B ......................................99 ART UILDING THE FRONTEND 5 Building user interfaces with React 101 5.1 React overview 102 JSX and React elements 103 ■ React components 103 Component hierarchy 104 5.2 Create React App 104 Creating a React application with Create React App 104 5.3 State and React Hooks 110 5.4 Exercises 114

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.