Global GraphQL Meetup
Low Code GraphQL With Neo4j
Building GraphQL APIs backed by a graph database is simpler than ever before with low-code tools like GraphQL Architect and database integrations for GraphQL and Neo4j. In this talk, we'll take a look at how to create GraphQL APIs backed by Neo4j using low-code tools as well as a look under the hood to see how these low-code GraphQL tools are built.
Links And Resources#
all right 00:05 and we're live let me go ahead and go 00:10 over here welcome to the graphql meetup 00:17 we are currently live uh we are here 00:19 with eve porcello 00:21 and william william leon and uh we're 00:24 pretty excited for 00:25 today's meetup let's go ahead and before 00:28 i get started talking about the few 00:29 things i want to talk about 00:31 i would like to introduce you to william 00:33 is it leon or lyon i'm sorry 00:35 uh lion like the like the anime yeah 00:38 william lyon yeah 00:40 sorry i took too much french in high 00:42 school and i was mad at it 00:44 the scottish it's the scottish version 00:47 not the 00:48 not the french version yeah yeah yeah 00:50 yeah so scottish cool william lyon 00:52 um so yeah if you want to tell us a 00:55 little bit just about yourself 00:56 um before we get started i'll give you 00:59 an introduction 01:00 we're just kind of letting some people 01:01 come on and while we still chit chat for 01:03 a little bit 01:05 yeah so um i work for a database company 01:09 called 01:09 neo4j which is a graph database 01:14 i work on a team that we call neo4j labs 01:16 which 01:17 builds plugins and extensions for neo4j 01:21 so try to enable developers to use neo4j 01:25 with different 01:26 technologies different frameworks solve 01:29 their their graph problems 01:31 and my focus for the last little bit has 01:35 been working on our 01:36 graphql integration which is what i'm 01:38 going to talk about today 01:40 see we're excited about it before we 01:42 talk about the graphql 01:44 integration we have to talk about that 01:46 tree in your background 01:47 which is really awesome 01:52 thanks yeah i needed a little bit of 01:54 christmas cheer in the office so we set 01:56 that up a few days ago 01:58 yeah sweet sweet i don't know if you can 02:01 see this but 02:01 um i didn't have uh a lot of ornaments 02:04 so i took some uh 02:05 some work stickers and made them into 02:07 ornaments yeah 02:08 oh nice 02:10 [Laughter] 02:12 oh wow we have a whole bag of conference 02:14 stickers i never even thought about 02:16 doing that that's genius because 02:20 yeah just put a little wire through them 02:22 and they hang out pretty nicely 02:24 yeah yeah yeah all right well i think we 02:26 have some 02:27 viewers on so i'm going to go ahead and 02:29 just get us officially started here 02:31 uh welcome to the graphql meetup uh i am 02:34 alex banks 02:35 you can find me at moon tahoe i co-host 02:38 this meetup with my partner and wife eve 02:39 porcello 02:40 you can find her at eve porcello 02:44 on twitter we host this meetup in 02:47 associations with 02:48 this.lab which is a software engineering 02:51 consultancy 02:52 um and today we have william lyon 02:56 with us um and if you were just here for 02:59 a second ago you heard that william 03:00 works at neo4j 03:02 um and we're really excited to hear 03:04 about 03:05 what he's going to be talking about 03:06 today so 03:08 without further ado i'm going to go 03:10 ahead and just change the screen 03:13 to william screen and 03:17 yeah whenever you're ready william we 03:19 can go ahead and get started 03:20 okay great well thanks for for 03:23 organizing and uh 03:24 thanks for having me on the title for my 03:28 talk is 03:28 low code graphql with neo4j 03:32 um you can find the slides at that link 03:35 on the screen there 03:36 my twitter handle is also linked there 03:38 which is a good way to get a hold of me 03:40 if you have any any questions or 03:42 or thoughts so here's kind of a rough 03:46 agenda 03:46 of what i'd like to talk about um 03:50 i want to give just a brief kind of 03:52 overview of what neo4j is and graph 03:54 databases in general 03:55 but uh talk more about 03:58 why it makes sense to use graphql with 04:02 neo4j 04:03 and then focus on how we can build 04:06 graphql apis with neo4j 04:08 take a look at some of the tooling that 04:10 we've built to make 04:11 building graphql apis with neo4j a bit 04:15 more 04:15 straightforward and then also kind of a 04:18 look behind the scenes 04:19 at how we build some of those tools 04:23 so that is the plan 04:26 so like i said my name is will i work at 04:29 neo4j 04:30 on what we call the neo4j labs team 04:34 which is focused on building plugins 04:37 uh integrations extensions with neo4j 04:40 and other technologies so i don't work 04:42 on the core 04:43 database itself and so i work on tooling 04:45 and integrations 04:46 around the database um oh i i recently 04:50 uh just started a newsletter also that 04:53 just kind of share 04:54 what i've been working on and 04:56 interesting things i've seen online 04:58 which is linked there at my personal 05:00 website slash newsletter 05:02 so if you want to keep up with what i'm 05:04 working on that's a that's a good way to 05:06 do it too 05:08 i've also been writing a book uh 05:11 published by manning 05:13 called full stack graphql applications 05:15 with grand stack 05:17 grand stack is graphql react apollo 05:20 and neo4j database which we'll talk 05:23 about 05:24 a little bit later uh this book though 05:26 is is a good overview of how to use 05:28 graphql with these different 05:29 technologies 05:30 um so it's a bit opinionated for 05:32 building a full stack application 05:34 using these tools it's available 05:37 in early edition from manning right now 05:40 there's also a free three chapter 05:42 excerpt that's 05:43 sponsored by neo4j that you can download 05:45 at grandstack.ioslash 05:48 ebook so if you want to see some more 05:50 in-depth content about some of the 05:52 things we'll talk about today that's a 05:53 good resource 05:56 okay so what is what is neo4j what is a 05:58 graph database 05:59 uh what are we talking about when we 06:01 when we say graph database 06:04 so neo4j is is a a database a database 06:08 management system 06:10 the main difference that you notice 06:13 initially when using 06:14 a graph database like neo4j is the data 06:16 model so rather than 06:18 tables or documents with graph databases 06:22 like neo4j the data model is a graph so 06:25 nodes 06:25 these are the entities relationships 06:28 connect them 06:29 specifically the data model that neo4j 06:31 uses is called the propertygraph data 06:33 model 06:35 we store properties or the the 06:38 attributes 06:38 on nodes and relationships 06:42 with neo4j we use a query language 06:44 called cipher 06:46 to interact with the database you can 06:48 see an example 06:50 on the screen there in kind of the upper 06:53 right 06:54 and cipher is all about graph pattern 06:57 matching 06:57 so we draw these sort of ascii art 07:01 notation graph patterns 07:04 and you can see here in in the example 07:07 we're saying 07:08 match on uh an address node so the 07:12 parentheses that indicates 07:13 a node and you can see we have this 07:16 incoming 07:17 registered address relationship that 07:19 we've drawn 07:20 as kind of like an arrow so that pattern 07:23 says find 07:24 an address where the address property 07:28 contains new york and then traverse out 07:32 to find officers that have a registered 07:34 address 07:35 uh in new york and then for those 07:37 officers find 07:38 the entities that they're connected to 07:41 um this this query comes from 07:42 the panama papers data set 07:46 which is a investigative journalism 07:50 project 07:51 that team the icij that analyzed the 07:55 panama papers data used neo4j to keep 07:57 track of 07:58 exactly this thing so offshore legal 08:01 entities 08:02 and officers connected 08:05 to them what else 08:09 the the other interesting things in the 08:11 neo4j ecosystem 08:12 are things like graph analytics so 08:15 representing your data as a graph that 08:17 means that there are lots of interesting 08:20 algorithms things like pagerank 08:22 community detection 08:23 things like this that you can do with 08:26 graph data as well 08:27 and then graph visualization is also 08:29 important 08:30 so being able to visualize your data 08:33 and make sense of it as a graph there's 08:36 also 08:37 graph database as a service offering 08:39 called neo4j aura and then 08:41 graphql integration which makes it 08:43 easier to build graphql apis 08:46 so there's sort of this this ecosystem 08:49 around 08:50 neo4j you think of it as sort of a graph 08:53 platform 08:54 that is interesting or say different 08:57 parts of it are interesting 08:59 for different users so if you're a data 09:01 scientist or a data analyst you be 09:03 you may be more interested in some of 09:05 the graph analytics 09:07 use cases and tooling if you're building 09:09 web applications 09:11 you're more interested in graph 09:13 transactions 09:14 and using the client drivers in 09:15 different languages 09:17 and this is where the graphql 09:18 integration comes in as well so 09:21 enabling you to build applications uh 09:23 using 09:24 a graph database is the idea there 09:29 let's look at a really quick demo 09:32 so i have a data set 09:36 loaded in neo4j running locally 09:42 this tool this is neo4j browser which is 09:46 like a query workbench for neo4j so it 09:49 allows me to 09:50 see what data that i have stored in the 09:53 database 09:54 and write cipher queries and then 09:56 visualize the results 09:58 so i can inspect my data so let's say 10:02 db schema visualization and i can see i 10:05 have 10:07 let's tweak our style here there we go 10:12 so this is the this oh that's cool yeah 10:15 this is uh sort of the meta model 10:17 of the database represented as a graph 10:20 so we have uh data 10:24 from of users who are connected to 10:27 reviews 10:28 reviews are connected to businesses so 10:29 this is like a like a business reviews 10:32 data set which i totally just made up um 10:36 but it's users writing reviews reviews 10:39 are connected to businesses businesses 10:40 are in a category so that's how 10:42 everything is 10:43 is connected and we can 10:46 write some queries here so let's find 10:50 a user named will 10:54 you can see here we draw this sort of 10:57 ascii art 10:57 representation of the node and in 10:59 parentheses i'm saying find a node 11:01 where the label so a label is a way that 11:04 we group nodes 11:06 you can think of it as kind of like a 11:08 table 11:09 from the relational world or a 11:11 collection from the 11:13 document database world and then 11:16 properties are represented within curly 11:18 braces so this says find 11:20 a node with the label user and the name 11:25 will so here's the will node i can 11:28 traverse out from 11:32 this node to find okay the reviews i've 11:34 written 11:35 what businesses what category are those 11:38 businesses in 11:39 so i can work the data that way i can 11:41 also write more complex queries 11:43 so here let's let's take a look at a 11:45 more complex pattern 11:47 i'll zoom in a bit so this says 11:51 find that user will and then traverse 11:53 out from that node 11:55 to find reviews that this user has 11:58 written 11:59 and then what businesses are connected 12:03 to those reviews 12:07 and so here's all of the reviews and 12:10 businesses that this user 12:12 has written and again i can traverse out 12:15 from here to find other 12:17 other pieces of the graph 12:20 what are some common use cases for graph 12:22 databases 12:24 well it's it's a natural way to 12:26 represent 12:27 our application data which is nice but 12:30 there are some 12:31 very specific use cases where graph 12:33 databases really excel 12:35 because they have different performance 12:37 characteristics of other databases 12:39 so graph databases are optimized for 12:42 these 12:42 traversals from one node to another and 12:45 a common 12:46 thing that we can do with these sort of 12:48 traversals 12:50 let me zoom in just a little bit so we 12:52 can see that query is 12:54 generate recommendation queries so if i 12:57 know 12:58 the reviews that a user or the 13:00 businesses that a user has reviewed what 13:02 category they're in 13:03 i can recommend businesses in that same 13:06 category 13:07 to my user that's a simplified version 13:11 of the type of recommendations that we 13:12 see in e-commerce 13:14 we can of course do much more complex 13:16 things like 13:17 collaborative filtering where i'm 13:18 looking at finding the most similar 13:21 users 13:22 what are they reviewing that might be a 13:24 good recommendation 13:25 that kind of thing but here we've taken 13:28 that 13:29 pattern that we wrote last time so find 13:30 all the businesses that 13:32 will reviewed now find what category 13:35 they're in 13:36 and then find other businesses in that 13:39 category 13:41 that this user has not already written a 13:43 review of 13:45 and score those according to the number 13:48 of overlapping 13:49 categories and that might be a good 13:51 recommendation 13:53 for this user so here's my three 13:56 recommendations based on that graph 14:00 query 14:02 cool so that's that's just a brief look 14:04 at neo4j 14:06 um and how we can interact with the 14:09 database using 14:10 cipher and uh in the browser and this 14:13 workbench tool 14:14 but you know most the time if we're 14:16 building an application 14:18 we don't want to you know directly 14:22 interact 14:22 with the database tooling like this this 14:25 web browser 14:27 we don't necessarily want to expose the 14:29 database to the world 14:30 we want to build some api layer so that 14:33 our 14:34 client application doesn't have to 14:35 necessarily speak cipher but can use 14:37 some 14:38 common uh way to interface 14:42 with the api and that is where graphql 14:45 comes in 14:47 um so graphql as you know exposes your 14:50 data 14:51 as a graph to the application layer so 14:55 you are thinking of your application 14:57 data as a graph 14:59 so when graphql was first open sourced 15:04 several years ago this was something 15:06 very interesting 15:08 for us at neo4j because we were 15:11 wondering okay 15:12 is is there a use case 15:16 uh for building graphql apis backed by 15:20 neo4j is this something people are 15:22 interested in doing 15:24 what sort of of tooling could we build 15:27 to make that process um easier and and 15:30 smoother 15:31 and so right away we started talking 15:33 with some users 15:35 both of of neo4j who are interested in 15:37 graphql and 15:38 in the graphql community and and trying 15:40 to figure out what made sense for some 15:42 sort of 15:43 database integration to build to make it 15:45 easier to 15:46 build graphql apis uh backed by the 15:49 neo4j database 15:51 this eventually became what we now call 15:54 grand stack 15:55 which is sort of this this full stack 15:57 framework for building 15:59 applications but the core of that is 16:01 really this 16:02 graphql neo4j integration 16:07 that we we sort of at a high level 16:11 um anyway early on from talking to users 16:14 figured out what were the 16:15 interesting features to build to solve 16:17 some of the problems they have 16:19 so at a high level things like reducing 16:22 boilerplate so 16:24 if you've written graphql resolvers by 16:26 hand there's a lot of 16:27 boilerplate data fetching code 16:29 oftentimes that goes in there 16:32 so improving developer productivity 16:34 being able to build 16:36 a functioning api more rapidly but that 16:38 also 16:39 is extensible so being able to add 16:42 custom logic 16:43 and make sure that it is performant as 16:46 well 16:47 so those were the the high level goals 16:50 and then specifically what we wanted to 16:52 do 16:53 was support this idea of graphql first 16:56 to development where 16:58 you start with graphql type definitions 17:01 you start with the graphql schema 17:03 and that can then define the data model 17:05 in the database 17:07 so rather than having to maintain two 17:10 schemas one for the api 17:11 one for the database instead you can use 17:15 graphql type definitions 17:16 to define the data model in neo4j and 17:18 because you're working with a graph 17:20 database 17:20 there's almost this one-to-one mapping 17:23 of the data model 17:24 in graphql in the database 17:29 we also knew we needed to auto-generate 17:33 all of the crud operations based on 17:35 these type definitions 17:36 so you tell us the types and the fields 17:40 and then our integration adds all of the 17:44 query and mutation fields that you need 17:46 for all of the 17:48 create update delete operations it also 17:51 adds things like 17:52 ordering pagination complex filtering 17:57 so here in this example i think we're 17:59 looking at some movie data 18:01 and filtering movies for 18:04 comedy zombie movies released after 1994 18:09 or animation movies starring 18:12 jesse eisenberg so you can you can 18:15 construct some fairly complex 18:16 filtering here out of the box you have 18:20 this the sort of functionality without 18:22 really writing any any code 18:23 at this point other than graphql type 18:26 definitions 18:29 so what about the the data fetching 18:31 layer 18:32 this you know we wanted to solve as well 18:34 we didn't want developers to 18:36 write a lot of data fetching code in 18:38 resolvers 18:40 so our graphic integration is able to 18:44 take an arbitrary graphql request and 18:46 translate that into 18:48 cipher so that query language we were 18:50 looking at earlier with neo4j browser 18:53 so then this means your resolvers are 18:55 auto-generated 18:56 and can take care of generating 19:00 a single query to send to the database 19:04 this is important because this addresses 19:06 some of the performance issues 19:08 that you commonly have with graphql like 19:10 the n plus one query problem 19:12 uh where you're often sending multiple 19:14 round trips to the data layer for a 19:16 graphql request because graphql is 19:19 this very nested um structure typically 19:22 so this also addresses that performance 19:24 aspect by letting the database 19:26 uh optimize the query uh 19:30 and just making one request so you don't 19:33 have that 19:34 network overhead of of making multiple 19:36 round trips to the database 19:39 so we talked about the 19:42 generated crud operations that gives you 19:46 basically the the crud api for free but 19:49 what about 19:50 custom logic how do you add how do you 19:53 add your own sort of business logic to 19:55 this 19:56 and for this we introduce what we call 19:58 the cipher schema directive 20:01 so schema directives in graphql allow 20:03 you to define 20:04 some custom logic that should happen 20:07 server-side 20:08 they're sort of graphql's built-in 20:10 extension mechanism 20:12 i think and what we've done here is 20:15 allow you to define 20:16 a cipher query that can be arbitrarily 20:20 complex 20:21 in this case this is a query generating 20:24 business recommendations so very similar 20:26 to the 20:26 the example query we looked at but we 20:28 can attach that to a field 20:30 in graphql and that then becomes a 20:32 computed field so 20:34 now when we request the recommended 20:36 field on the business node 20:38 we run this cipher query to find similar 20:41 businesses 20:43 for this user so that allows us to sort 20:45 of extend the functionality of 20:48 graphql using power of cipher for custom 20:51 logic 20:54 there are a few implementations of this 20:57 integration one neo4j graphql js 21:01 which is targeted for node.js 21:05 graphql applications it works with 21:08 any of the javascript graphql server 21:11 implementations so like apollo server 21:13 yoga some of the apollo server lambda 21:17 as well there's a java version of this 21:20 for java graphql apis 21:23 and then a database plugin as well so 21:26 you can actually serve the 21:27 graphql api from the database itself the 21:31 documentation and examples for all this 21:33 are on the grandstack.io site 21:38 so what we're we're talking about here 21:41 if we look at 21:41 neo4j graphql.js is it's important 21:44 distinction we're not really talking 21:45 about making the database 21:47 speak graphql um graphql is not a 21:50 database query language 21:52 uh we and there are still cases where it 21:54 makes sense to have this three-tier 21:55 architecture to have this api 21:57 application that sits between 21:58 the client and the database where i can 22:00 do things like enforce 22:02 application authorization logic caching 22:05 these sorts of things so we're very much 22:07 talking about 22:08 a library that makes it easy to build 22:10 this api layer that sits between the 22:12 database 22:13 and the client if we look at 22:17 the sort of the the functionality of 22:21 these graphical integrations 22:22 there's roughly two aspects one is the 22:25 schema augmentation 22:27 where we're adding the query mutation 22:30 fields 22:31 adding input types things like that and 22:33 then the 22:34 graphql transpilation layer where at 22:36 query time 22:37 we're taking a graphql request 22:39 translating that to cipher 22:41 and also handling that data fetching 22:44 logic from the database 22:47 let's take a look at an example that 22:50 uses this 22:51 neofj graphql js library so i have a 22:54 code sandbox here 22:57 that will fire up and this 23:00 is going to spin up a graphql api 23:03 talking to 23:05 some neo4j instance that we have hosted 23:08 in the cloud 23:09 somewhere so this is the connection 23:10 string for that database 23:13 this is just a read-only user so don't 23:15 worry about 23:17 my username and password being in there 23:19 just a demo 23:22 so if we look at the code for this 23:26 we're pulling in this make augmented 23:29 schema 23:30 function from the neo4j graphql js 23:32 package 23:34 we're pulling in apollo server and we're 23:37 pulling in 23:38 the neo4j javascript driver and then 23:41 some some 23:42 helper utilities so the first thing we 23:44 do is read our type definitions 23:47 from the schema.graphql file which is 23:50 here 23:51 so here we've defined graphql type 23:52 definitions for 23:55 user reviews businesses categories so 23:58 a similar data model to what we were 24:00 looking at in neo4j 24:03 and then we pass those type definitions 24:05 to this make augmented schema 24:08 function and that gives us a 24:11 graphql executable schema object that we 24:14 can then serve 24:16 with apollo server we also create a 24:19 connection to the database this database 24:21 driver instance and we inject that into 24:24 the 24:24 context object so that this driver 24:27 instance is then available 24:29 in the graphql resolvers um 24:33 but what resolvers i guess you might say 24:35 so notice that we didn't write 24:36 any resolver functions when 24:40 we generated our schema we just passed 24:42 in our typedefs and that's what this 24:44 make augmented schema 24:46 export from the neopj graphql js package 24:48 is taken care of it's generating 24:50 the resolvers for us based on our 24:52 graphql schema 24:55 so if we go to graphql playground let's 24:58 open this in another tab 25:03 and here let's start off with a simple 25:05 query 25:06 just find businesses 25:10 and their name there we go 25:16 so we come back with a list of 25:17 businesses we can add address and so on 25:22 and if we look at code sandbox 25:26 in the console we can see here the 25:28 generated cipher query 25:30 that's being uh being generated so here 25:33 if we're requesting 25:35 uh to find businesses name address let's 25:38 add 25:40 um categories 25:45 we can see at query time that query is 25:49 being generated 25:50 uh to find just the data that we're 25:52 looking for traversing 25:54 neo4j to find that data we can also like 25:57 we said 25:58 add custom logic with this 26:01 cipher directive field so here we have 26:04 this recommended field 26:06 it is bound to a cipher query that's 26:09 finding similar businesses based on 26:13 users that have reviewed it so find all 26:15 the users that have reviewed this 26:17 business 26:17 what other businesses are those same 26:19 users reviewing 26:21 that's a good indication of a 26:23 recommendation for a business you might 26:25 be interested in 26:26 if you're interested in this business so 26:28 then i can add 26:31 that recommended field now to our 26:36 selection set and so 26:37 this is saying if you like missoula 26:39 public library 26:41 you might like ninja mics which is just 26:43 a couple blocks away from there 26:45 and if we look at our generated query we 26:48 can see now that that 26:50 recommended queries but hard to read so 26:53 in the console here but 26:54 this uh this query that we've now 26:57 attached to our 26:58 recommended field uh runs as a sub query 27:02 with our generated 27:03 cipher query for along with the other 27:05 fields that we requested 27:07 so still just one round trip to the 27:09 database 27:10 which is pretty cool i think 27:15 that's interesting and if the if that uh 27:19 yeah can you go back to the code really 27:21 quick so we can see where the cipher 27:22 goes in 27:27 so that's pretty neat there looks like 27:30 you have a cipher directive with the 27:31 statement 27:32 yeah exactly and and this can be any any 27:35 arbitrary 27:36 cipher statement with whatever sort of 27:38 logic we want to add and 27:40 we can do this on at the field level 27:43 we can also do this for custom 27:46 mutations and query fields as well so if 27:49 we have 27:50 a special way that we want to create 27:52 data instead of the generated mutations 27:54 we can do that 27:55 if we want to do something like use a 27:57 full text index or something like that 27:59 for fuzzy matching we can do that on 28:01 query fields 28:02 as well so we have a question 28:05 right here for you and i know that um i 28:07 don't want to interrupt but since we're 28:08 talking about this 28:09 right at this point i feel like it's a 28:10 good point 28:12 so the question is is there a reason why 28:14 it's translated into cypher 28:16 and if you wouldn't mind just taking a 28:17 second to let us know like the value of 28:19 using cipher 28:20 uh within your graphql schema here 28:22 that'd be great 28:25 yeah so i guess there's um 28:30 there's sort of a high-level reason 28:33 um that we translate graphql and 28:35 decipher and 28:37 that is you know 28:40 that graphql is not really a database 28:43 query language so we can't just send 28:45 graphql to the database directly to 28:50 to fetch data from the database and 28:54 we with neo4j we use this query language 28:57 called cipher 28:59 the benefit that you have there is very 29:02 easily being able to express 29:04 this idea of what in a relational 29:06 database you would call a join or or a 29:08 traversal 29:10 in graph parlance which is sort of 29:13 traversing from one node 29:14 to another node so in in cipher that can 29:17 be expressed just with this sort of 29:19 simple 29:19 ascii art pattern and something like sql 29:22 you have to write a join 29:24 statement to do that it's a bit more 29:26 complex both at the query language level 29:28 and also at the 29:30 actual data store level um 29:33 so we also don't want to just expose our 29:36 database 29:37 to the world and say you know 29:41 the client can create its own arbitrary 29:44 cipher to send to the database to find 29:48 business recommendations right so we 29:50 want to encapsulate that logic 29:52 in our graphql api so being able to 29:55 attach these cipher statements at the 29:58 schema level 30:00 allows us to take that custom 30:02 functionality 30:04 attach that in our graphql server layer 30:07 and then that implementation is not 30:09 exposed 30:09 to the client right so if i'm a a 30:12 consumer 30:13 of this api to me recommended 30:16 is just another field that returns 30:20 a list of business objects i don't know 30:23 that 30:24 there's this cipher query that's 30:27 bound to this field graphql 30:30 schema directives are not currently 30:32 exposed through 30:33 introspection so i can't introspect this 30:37 api 30:38 and see that there's this cipher 30:40 directive here so 30:42 anyway so that's nice that fact that you 30:45 can't introspect 30:46 a graphql api to see the schema 30:49 directives 30:51 also means that it's nice to be able to 30:53 express some of your 30:54 authorization rules in schema directives 30:57 so you wouldn't wouldn't necessarily 30:58 want to expose 30:59 the authorization rules for your api 31:03 to anyone and it's a common pattern and 31:05 we use this in the near graphql 31:07 integrations 31:08 to add authorization rules as schema 31:10 directives as well 31:11 right sorry a bit of a rambling answer 31:13 but that's great thoughts on that 31:19 cool so that is 31:23 a little look at how we use the neo4j 31:26 graphical js 31:27 integration um i want to talk a little 31:30 bit 31:30 about how we build 31:34 that integration and this is how a lot 31:37 of 31:37 graphql database integrations are built 31:41 and that is making use of what's called 31:43 the resolve 31:44 info object so every resolver 31:47 is passed this object called resolve 31:50 info 31:51 that contains a whole bunch of 31:53 information about 31:55 the graphql schema and the 31:58 current graphql query that's being 32:00 resolved 32:01 so it has a representation of the entire 32:04 schema 32:05 it has an ast that's abstract syntax 32:08 tree of the current 32:12 graphql query 32:15 those those are the most important 32:17 things that we're interested in 32:19 you can see we also have the value of 32:21 the graphql variables the 32:23 fields that have been traversed so far 32:25 to get to 32:26 the resolver that that's currently been 32:28 called so all of this is in 32:30 this graphql resolve info object 32:33 and we can inspect that object to 32:37 find basically the nested selection set 32:40 of the query 32:41 and this is important because once we 32:42 have that then from 32:44 the root resolver so in the case of a a 32:47 query operation 32:48 we can generate a single database query 32:52 to resolve that entire nested selection 32:54 set in 32:55 in one database query and we also use 32:57 this to implement the 32:59 that cipher schema directive which i'll 33:01 talk about in a second 33:02 right so that's the idea as we go from 33:04 the resolve info object 33:06 inspect the query ast find what the 33:09 nested selection set is 33:10 and then iterate through that object to 33:13 build up this database query 33:15 and you can apply this logic to to 33:18 cipher 33:19 to sql or to other 33:22 database query language languages cipher 33:25 though has a 33:26 a nice feature called a map projection 33:29 which allows us 33:30 to shape the return structure of the 33:34 database query 33:35 to match exactly the selection set in 33:37 graphql 33:38 so just like in graphql where you're 33:41 only returning 33:42 the fields that have been requested in 33:44 the selection set 33:45 we can do that in cipher as well and 33:47 return 33:48 an object basically that matches exactly 33:50 the data that 33:52 our graphql server expects to to be able 33:54 to resolve the 33:55 graphql request 33:59 we can also inspect which fields 34:02 have these cipher directives on them so 34:06 that when we 34:06 are generating the the query 34:10 we know to look for what is in the 34:13 statement argument 34:14 in the cipher schema directive and 34:17 rather than 34:17 try to fetch that field directly from 34:19 the database we basically 34:21 just inject the user-defined cipher 34:24 query 34:26 here as a subquery so then that becomes 34:29 part of the overall generated query 34:32 in this example was looking at uh for a 34:35 conference 34:36 recommended sessions uh so similar to 34:39 our business idea if you're interested 34:40 in this session here are other 34:41 sessions you might be interested in 34:46 uh this is this is kind of a 34:49 non-standard i don't want to say weird a 34:50 non-standard way of implementing schema 34:52 directives i guess it's 34:54 it's useful if you are using the schema 34:57 directive 34:58 as sort of storing metadata essentially 35:01 it's not the standard way of 35:03 implementing schema directives 35:04 you might use the 35:09 schema directive visitor from graphql 35:11 tools 35:12 to build schema directives and this is 35:14 what we we use for building 35:16 those authorization schema directives 35:18 that i mentioned so being able to add 35:21 authorization rules using a schema 35:24 directive 35:25 to define what users should have access 35:28 to 35:29 what information and operations 35:31 essentially 35:34 if you're interested in this i gave a 35:35 talk at graphql summit 35:37 last year that dives into this in a bit 35:40 more detail 35:41 so the link to that video is here i 35:44 think i also wrote a blog post which i 35:46 can link here as well that 35:47 goes in into this in a bit more detail 35:51 okay so i i thought we're going to be 35:52 talking about low code 35:54 graphql we've we've seen a lot of code 35:57 so far 35:58 so what's what's going on here uh what's 36:01 the scam 36:01 well you know i think that low code 36:04 is uh this buzzword that we hear a lot 36:08 recently and in my mind there's really 36:12 this spectrum of low code is the way i 36:14 think about it 36:15 like at the end of the day developers 36:18 don't really care 36:19 about buzzwords like they're they're 36:21 more interested in in solving problems 36:23 so i like to think of low code as 36:26 anything that 36:27 solves my problem uh that involves me 36:30 writing 36:31 less code as a developer so i think of 36:33 it as 36:34 this spectrum of low code that is 36:36 anything from 36:37 like libraries packages integrations 36:40 like nifty graphql js 36:42 that's low code in the sense that well i 36:43 don't have to write resolvers 36:46 and i can just sort of attach cipher to 36:49 my schema 36:50 and add custom logic so that's less code 36:54 than like writing those resolvers by 36:56 hand and reducing boilerplate 36:58 then there's things like clis so one 37:01 thing i haven't talked about yet 37:02 are some of the clis that are available 37:05 like create grand stack app 37:06 which a lot provisions a full stack 37:08 application 37:10 the grand stack cli which has more 37:12 utility functions 37:14 and then at the other end of the 37:16 spectrum are 37:17 ui driven tools which we'll talk about 37:20 in a second 37:20 like graphql architect which allows us 37:23 to 37:26 build query and deploy graphical apis 37:30 without writing any code other than 37:32 graphql type definitions so 37:34 that's how i think of things as kind of 37:36 this low code 37:38 spectrum since i mentioned the the clis 37:43 talk a little bit about that or about 37:46 two of those clies one is the 37:48 create grand stack app uh which is great 37:50 for provisioning the skeleton of a 37:52 a full stack grand stack application and 37:55 then the grand stack cli 37:56 which allows us to do things like infer 38:00 the type definitions from an existing 38:01 database and generate those 38:05 i think we have a screen cap here of 38:07 using 38:09 create grand stack app 38:12 maybe but if you've used create react 38:16 app it's it's a similar idea or if you 38:18 create next app similar idea uh where 38:21 you run this 38:24 command and um maybe we'll 38:28 skip our screencast here 38:33 similar idea when you run this command 38:35 answer a couple of interactive 38:36 questions do you want to provision a 38:38 database you have an existing database 38:40 what are the credentials that sort of 38:41 thing 38:42 and provisions out your application uh 38:46 for you 38:48 and then the grand stack cli which is 38:50 more of like a 38:52 utility cli that i can point at a 38:54 database 38:55 generate type definitions point a 38:57 database start a graphql api 39:00 assert the schema for the api these 39:03 sorts of things 39:05 and then built on top of those clis we 39:07 have 39:08 graphql architect which is 39:11 sort of a plugin for neo4j desktop 39:15 that allows us to build query and deploy 39:18 graphql apis so we'll take just a really 39:21 quick 39:22 look at this tool so this is 39:26 neofj desktop this is like the 39:29 mission control i guess for neo4j so it 39:32 allows me to 39:34 download neo4j databases to point them 39:37 at putting these projects at remote 39:41 databases that i have hosted 39:42 somewhere but it also has the ability 39:45 for running 39:46 what we call graph apps which are 39:49 really like plugins for neo4j desktops 39:53 so single page apps 39:54 that allow me to interact with neo4j 39:56 databases 39:57 so the ufj browser 40:01 where i was writing cipher queries and 40:02 visualizing the results that's a graph 40:04 app 40:05 but another one that i'm going to launch 40:07 now is graphql architect 40:12 in graphql architect the idea here is 40:15 when i point it at a database it 40:18 inspects the data model 40:19 of the database and generates graphql 40:22 type definitions 40:24 that define a graphql api 40:27 for the data in this database so it 40:30 immediately detected that i have this 40:32 business reviews data set and it gave me 40:35 a user type a review type 40:37 category business what are the fields on 40:40 it how are those fields connected 40:43 by relationships so i can just click 40:46 start to start a graphql api 40:49 locally and then switch over to 40:52 graphical 40:53 i can see here all the query fields that 40:56 have been added for me 40:58 and just immediately start querying the 40:59 database um so 41:01 this is similar to what we saw with that 41:03 code sandbox 41:04 example and then i can add 41:11 computed fields here so similar to what 41:14 we were doing 41:15 with adding those cipher directive 41:18 fields 41:19 hit restart and then those fields are 41:21 available 41:22 so have a nice low code iterative 41:26 development process where i don't have 41:27 to worry about okay what is the actual 41:30 like node.js javascript code to define 41:32 and build this graphql server 41:34 everything is driven from these graphql 41:37 type definitions 41:39 and then when i want to deploy this 41:40 somewhere 41:42 currently this uh can 41:46 export to github essentially so i have 41:48 this um 41:49 synced with a github repo as i make a 41:51 change it makes a commit 41:53 to the github repo with a change in the 41:55 schema file which i can then hook into 41:57 something like 41:58 netlify or versel to trigger a 42:01 deployment of my 42:03 of my api and that 42:07 so that is available at 42:09 install.graphapp.io which also has 42:11 a whole bunch of these other interesting 42:12 graph apps for 42:14 neo4j that i can install as well 42:22 cool so that is pretty much all that i 42:26 i have today i'll mention just a couple 42:28 of resources 42:29 if you're interested in learning more 42:31 about this um 42:33 grandstack.io is the site that has a lot 42:35 of documentation 42:36 and tutorials some more information on a 42:40 lot of the things i talked about 42:41 today i mentioned the the book that i've 42:44 been writing that's available now in 42:45 early release 42:46 and the free excerpt that is available 42:50 at grand stack dot io slash ebook 42:54 i've started doing live streams more 42:57 recently which is 42:58 uh has been kind of fun for me on the 43:00 neo4j twitch channel 43:02 we've gone through the process of 43:04 building a few 43:06 grand stack applications from scratch so 43:08 we built a real estate 43:10 search application um i think we're 43:13 gonna start 43:14 a podcast application uh this week so 43:17 it's every thursday at 2 p.m pacific 43:21 time 43:22 so if you're interested in learning more 43:23 about using graphql and neo4j that's a 43:25 good resource as well you can watch me 43:27 kind of 43:27 fumble along building an application and 43:30 then 43:31 like i said uh twitter is is probably 43:32 the best place to get a hold of me 43:36 cool you guys have been really busy over 43:39 there that was a lot of neat stuff 43:40 i particularly like the visualizer um 43:44 uh the graph visualizer to me i'm just 43:46 like it looks like an incredible tool 43:48 for 43:49 um just teaching what graphs are and 43:51 what not 43:52 um so i was really excited about that um 43:56 sweet well does anybody have any 43:57 questions 44:00 for william i can give us a couple 44:01 seconds for that um 44:04 and if not i guess that will just bring 44:08 us to 44:08 an end here so we want to thank you for 44:10 attending the graphql meetup again you 44:12 can find me on twitter at 44:14 moon tahoe uh eve is on twitter at eve 44:17 porcello 44:18 you can also look us up at 44:19 moonhighway.com and at moon highway we 44:22 teach javascript to software engineers 44:24 of all skill levels 44:25 so we build curriculums we have classes 44:28 uh and we teach in the classroom too so 44:29 if you 44:30 want to get in touch with us on any of 44:32 that please feel free to reach out 44:34 um yeah and that brings us to the end of 44:37 the day 44:38 um let's see here 44:43 so we do have a question in the chat 44:47 and it says that the graphql type system 44:49 validates all input relative to the 44:51 schema 44:52 and the generated cipher queries are 44:53 always parameterized okay it looks like 44:55 i guess we're answering a question 44:56 from earlier in the chat here so i just 44:59 read that answer from the chat 45:01 um so i will leave the chat up here for 45:03 a few minutes uh 45:04 if you want to continue to chat and uh 45:06 ask any questions about grand stacked or 45:08 or neo4jf uh but that brings us to a 45:11 conclusion of this meetup thank you so 45:13 much william 45:14 um a lot of good information thanks for 45:17 organizing thanks for having me on and 45:18 thanks everyone for joining 45:20 great thank you 46:04 you
Subscribe To Will's Newsletter
Want to know when the next blog post or video is published? Subscribe now!