 Hi everyone My name is Victor and I'm here to talk about Pineton and specifically with you graph QL To start I'm not the creator of I'm not have any involvement with Facebook on the creation of graph QL and I'm not either the creator or developer of the graphene that it's one of the Libraries that I'm going to show how to use with to implement graph QL in pint on Django. I'm just a user And what is graph QL? Does anyone in here use graph QL today? No, right. Yeah, so graph QL is a new query language created by Facebook and Open-sourced like recent. I believe that it was created in 2012 and open source like last year Some call it's a framework as well. I think that it's more a language and specification Facebook released as well few frameworks and few helper libraries to allow people to use to help people using Graph QL, but it's more language to Kind of take place of what today we we call rest framework rest APIs and bring peace between back-end developers and client developers Why graph QL? We all are used to rest frameworks and We are happy today with a Ajax calls and Transparen Jason after years of XML and soap web services But it's still it's not perfect As the time passed by we see ourselves versioning our APIs with API v1 API v2 API v whatever you call it and it's become hard to maintain and This is not a problem of Django. This is not a problem of Django rest framework This is just the way that rest it's laid off those that there's no really a Way to fix this but changing rest and Create a new query language specific for web the other problem that we see is that we start exposing a model and In the simplistic way in the academia we can it looks like per simple you have a user model that you create a user serializer and You do a get in the users you receive a list of user you do a post you create you do a get users ID you receive an object. That's pretty beautiful looks beautiful in the tutorial, but in the real world You need to serializers. There is the user serializer and another serializer with less detail that you send to your API listing and Then there's the start-up Way that they need few extra ways because that your iOS developer may require three different ways of seeing your users and After few months you have a same model with 10 different ways of rendering that and It's clearly for anyone that's working the back inside that this is not great and this is not the right way This is what we see a lot when we are working specifically with startups that try to reinvent themselves prototype their product so quickly and on applications that are already on Apple Store and Google Play and You cannot afford to simply Kill your old model or kill the old way that you are rendering your model for your clients Because you have no control over when your client is going or if he will ever update the client So you end up having to keep all this versioning of API's and all these Different ways of rendering the same model This become a mess with time So But yeah, we all love Django REST framework. It has been I believe the standard for Django for quite a while Few years back I still play around a little bit with taste pie another library to create an REST for API APIs, but I feel that as of today I'm not the only one thing that almost a hundred percent of the Django project has a Django REST framework on then and It's amazing like over six thousand Stars on github two thousand forks Not even count how many stack overflows and Google account Instances you can find so Yeah, Django REST framework is amazing, but it's not the problem of the framework is the problem of REST for API's It's not matter how great is your your API but when you have your iOS developer with a different need of your Android developer and your web client and one unique backend trying to Adapt to all of this tree your REST API May end up not being as restful as you plan at first So anyway, thank you Tom Christie for the great work with Django REST framework But we need something else and This is GraphQL The way to get started with GraphQL I would say is yeah Dig a little bit in the documentation. It's a completely different sort of a specie so You won't be using just Ajax calls you have to get used it to what are the types available for a GraphQL What is an basically? I think that the main stuff to getting started someone need to understand the types available What is a node? What is a query in a little in a little bit of what is relay at least to understand the terminology? It's almost like If you were getting a start with REST for API, you need to know what is a get what is a post? What is an endpoint? Those basic things when you move to GraphQL, you need to know what is a node? What is a query? as the name says it's kind of Exposing our models as a graph the data structure graph so instead of roles or instead of JSON objects you're going to have a node that will be almost as an instance of your object and the query being the main endpoint and The difference one of the main difference like just to start is that you have just one endpoint It's one root endpoint that is your query and from there You can choose what to query It's almost like bringing the power of SQL to the web allowing the user not just to get The information s was specified by the back end, but choosing what he wants choosing the fields that I want Choosing the relationships and filters that I want to use Another great way to get started and if you are Star Wars fans You may get hooked into a little bit. There is the GraphQL Star Wars API The github project. It's so it's Available so you can see the entire source code and if you just want to play around with the the project deployed There's this link that has the project deployed and you can check it out and play a little bit with that and After you understand a little bit of the query language itself The second part that is a little bit I feel it's not as important as at this moment because most of the times we most of the problems that we have with rest is During the process of querying not in the post in itself our post request usually has less changes than our queries and But it's in but it's somewhat important as well is the in GraphQL we call the post Mutations so if you want to know as well how implement how to Change data how to create data through the GraphQL you may need to learn how to implement the mutations in your GraphQL API So you look into that you loved it you sign in how can I start now doing with Python because when you go to the GraphQL documentation you find that there is a framework for Node.js. There is a framework for I believe that Ruby and Everything else that you may imagine but there's no links for Python on the official documentation created by Facebook well there is a project called graphene That implements GraphQL in Python and it has as well a wrapper for Django and it's as simple as a pip install graph in Django and graph graphic Graphical Django graphical This is not mentored the second line. It's just a way to have the web view the react web view that allow you to play around with your graph API and After that you create your app in your models this sorry this is Following as if we are doing a Django project. So you install graphene you start graphical and You create your app your models as you would in any Django project But everything installed apps and then let's start with doing the GraphQL The first part of a project with GraphQL is Creating your nodes It has the Django node class that allows you to explain the type of objects that your GraphQL will have and If you take a quick look into this it kind of reminds me a little bit model view sets or Django REST framework serializers where you specify what model is it this node is is going to inherit off and some extra parameters as filters and Order by and what else you may imagine there are plenty of options. Those are the most basic ones and This basically tells your GraphQL how to represent a user After that you have to create the the root for your For your GraphQL and the root it's almost as if Compared with the URLs sort of so the idea is that each app will have its own query and You have a main it's let's win with Django each app has its own URL and The project has the main URLs that import all the URLs and includes them In the path for the project The same will be applied with GraphQL the standard way of doing you create one Roots that will be one schema for each app and This schema will expose Them the nodes of that specific app. So let's pose in this case We have a user's app with a user model So we create a user node first and then we created this schema that we will expose that user mode No, sorry You see that it has a class method abstract through is because we we don't really want to use this Class query yet. It's an abstract that will be imported by the global query That would be almost as the global URLs dot pi that you include the URLs from your app later So where we go after this? Now we create our global query This in the official documentation. I believe that they lay out these are this file Aside the manage dot pi in the root of your project. I believe that it's for my point of view, I'd had her put inside your project app folder Let's pose when you create a Django project. It's by default creates the Project and within the project. There is a folder with the name the same name of the project that has your Settings and your the main URLs and everything I had her put in there Then in the roots together with manage dot pi I know that some people that use cookie cutter and or some people rename that That folder as well to config most of the time that will have your main settings of Django I had her put it in there in that folder in this config folder and On these schema, you are going to import your app schema. Let's pose users dot schema and Then expose your model to the To graph ql doing so You just need to Plug in your URLs because you have a schema. You have the queries, but Django still does not know how to route those graph ql and The way for doing so is by Plugging the schema created to the Django URLs The other thing that it's not mandatory, but For anyone that are planning on start playing around with graph ql. It's extremely recommended is To add that graphical that is the second line in the In this URL pattern that I created the and these will include that react webvill for you to play with The graph ql it's really a web console that you can type your query in one side and get the results in the other side To get started and playing around on the production. It's not necessary. It's just for playground but I think that it's It's the best way to really get started and to learn some how to do some queries and stuff You may want to protect this somewhat if you are if you put in this expose to in a real server You can just add some permissions to just add means or some specific low group to be able to access that and After that you're done. You have your graph ql Exposed and You can access the graphical and you have an interface like this that we will allow you to query the Your Graphql through the web This is not how your clients are going to use But this is the first way to get started with graphical to really write in the queries and playing with that the Clients itself your iOS developer Your react developer or whatever client you may have they will call straight this first line that is the graph ql and the point and passing the the query that they need I've gone and Why not? What are the problems looks like too perfect to be true and It's in early stage. I think that For some of us it may look amazing We got we like to see new things we like new technologies We like to play with new things, but it has the downsides. It's a technology that you may expect to change a lot and The adoption is not as high as a RESTful or Django REST framework We your team user that's one big problem It's not just we if you implement this in your Django back end it may work perfect, but If your client is not willing to implement that on the iOS application if he Your clients is not willing to implement the web application. It just pointless You need to sync you need to know that your clients really willing to do that for example on my case I work I have a full-time job and And we There's no way that we can use that in there like in my company And in the other two freelance projects that I work One of them the iOS developer is a little inclined of using it But still it's just inclined no one is really Using much so I'm still do not have in any project on that I'm on production with this because it does not matter if I haven't end point ready No, no clients is Not that the clients iOS skin works very well with GraphQL But if your iOS developer is not developing with I with GraphQL I'm sorry. You have to try to sell in the idea and it's not at ease some time and I think the major problem is help as I mentioned before you see the amount of a stack overflow questions and the number of tutorials that we have about Django REST framework and Almost every single problem that you may imagine you will face when implementing API with Django REST framework You can find someone that had the similar problem or close by and you can Kind of relate with that and it's easy to find the help when you are doing GraphQL you are in your all so You are going to spend a lot of time sometimes a lot of hours just to sometimes fixing small mistakes that You did and just no one else did before you are no one share that with you yet This is a big problem sometimes I Believe that that's it. This is the way to get started and I just have to mention that Cyrus Akibari, I don't I don't know exactly his name He was the creator of the graphene that is the wrapper for Python and GraphQL And I believe that he will be at Django conference in Philly this week giving a talk So if someone is interested I Definitely recommends it's a great library and on this sample that I showed it's most It's just using the Django part, but it's not a Django library. It's a Python library You can use it with flask you can use with pure Python and SQL alchemy the advantage of using with Django at least for me as a Django developer is the fact that it can inherit in my my existing models and So my work it's kind of close to the same work that I would have when I'm doing a REST API of creating my model view sets or or Model serializers and specifying some extra parameters, but I don't really need to create the entire model again That's I think that's it for for now if anyone has questions of a query I do not let me see if I have any yes Yeah, the the Star Wars API. I believe that's the best sample and Oh, wait, I don't have Wi-Fi What I recommend to get started with the language if you usually when you if you want to see samples of queries itself When you open the Star Wars project there is the test files That and the test files have Plenty of query samples of course to test and it's an easy way to get started but the format itself it's something and then This interface that we are using is the graphical It's the one that I said that Jenga REST framework implements as well, and it has this helpers that will kind of autocomplete your your comments and allow you to to play around with your with your queries Oh and In here we can get in this case, I'm using the old films and As you can see we can specify the fields that we want so we solve that first problem of the REST API that each client Requests you to have a different fields your iOS developers say that he cannot receive the members and your Android developers say that he would love to have the profile picture and Each one can ask for the fields that they want kind of the same way that whoever is used to SQL We were used to specify what we want. We would not just get whatever the API give us and Let me see in here you can Let me see what's the relationships that is have Okay, any any other question anyone and Yeah So thank you all. I hope you guys enjoy and use the graph well