Skip to content

Instantly share code, notes, and snippets.

View chris001177's full-sized avatar

Chris chris001177

  • india
View GitHub Profile
# cookbook/ingredients/schema.py
import graphene
from graphene_django.types import DjangoObjectType
from ingredients.models import Category, Ingredient
class CategoryType(DjangoObjectType):
class Meta:
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)),
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
# cookbook/ingredients/schema.py
import graphene
from graphene_django.types import DjangoObjectType
from ingredients.models import Category, Ingredient
class CategoryType(DjangoObjectType):
class Meta:
# 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
import React from 'react';
import { Query } from 'urql';
const getTodos = `
query GetTodos {
todos(limit: 10) {
id
text
isDone
}
<Query query={q} requestPolicy="cache-and-network" />;
/* or with hooks: */
useQuery({ query: q, requestPolicy: 'cache-and-network' });
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) {
import React, { Component } from 'react';
import { Mutation } from 'urql';
const addTodo = `
mutation AddTodo($text: String!) {
addTodo(text: $text) {
id
text
}
}
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