This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # cookbook/ingredients/schema.py | |
| import graphene | |
| from graphene_django.types import DjangoObjectType | |
| from ingredients.models import Category, Ingredient | |
| class CategoryType(DjangoObjectType): | |
| class Meta: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.conf.urls import url, include | |
| from django.contrib import admin | |
| from graphene_django.views import GraphQLView | |
| from cookbook.schema import schema | |
| urlpatterns = [ | |
| url(r'^admin/', admin.site.urls), | |
| url(r'^graphql$', GraphQLView.as_view(graphiql=True, schema=schema)), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import graphene | |
| import ingredients.schema | |
| class Query(ingredients.schema.Query, graphene.ObjectType): | |
| # This class will inherit from multiple Queries | |
| # as we begin to add more apps to our project | |
| pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # cookbook/ingredients/schema.py | |
| import graphene | |
| from graphene_django.types import DjangoObjectType | |
| from ingredients.models import Category, Ingredient | |
| class CategoryType(DjangoObjectType): | |
| class Meta: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # cookbook/ingredients/models.py | |
| from django.db import models | |
| class Category(models.Model): | |
| name = models.CharField(max_length=100) | |
| def __str__(self): | |
| return self.name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from 'react'; | |
| import { Query } from 'urql'; | |
| const getTodos = ` | |
| query GetTodos { | |
| todos(limit: 10) { | |
| id | |
| text | |
| isDone | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <Query query={q} requestPolicy="cache-and-network" />; | |
| /* or with hooks: */ | |
| useQuery({ query: q, requestPolicy: 'cache-and-network' }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { Component } from 'react'; | |
| import { Mutation } from 'urql'; | |
| const addTodo = /* ... */; | |
| class TodoForm extends Component { | |
| add = () => this.props.addTodo({ text: 'something!' }); | |
| render() { | |
| if (this.props.error) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { Component } from 'react'; | |
| import { Mutation } from 'urql'; | |
| const addTodo = ` | |
| mutation AddTodo($text: String!) { | |
| addTodo(text: $text) { | |
| id | |
| text | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from 'react'; | |
| import gql from 'graphql-tag'; | |
| import { Query } from 'urql'; | |
| const getTodos = gql` | |
| query GetTodos($limit: Int!) { | |
| todos(limit: $limit) { | |
| id | |
| text | |
| isDone |