Skip to content

Instantly share code, notes, and snippets.

@austincollinpena
Created February 23, 2020 06:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save austincollinpena/3044c6fc4e7e36a1ba0a5cb552b1e28b to your computer and use it in GitHub Desktop.
Save austincollinpena/3044c6fc4e7e36a1ba0a5cb552b1e28b to your computer and use it in GitHub Desktop.
Pass an argument to a function via a graqphql mutation and return a new value
# Packages: Django-graphene, django
from graphene_django.types import DjangoObjectType
import graphene
class FetchTwilioToken(graphene.Mutation):
# Define the arguments that are passed from the client in the mutation
class Arguments:
identity = graphene.String(required=True)
# Define the arguments that might be returned that are not defined
# elsewhere. Give them a graphene type
new_token = graphene.String()
def mutate(self, info, identity):
# These two lines of code are just grabbing a JWT via an internal
# package
new_token_getter = GetTwilioAuthToken(identity)
new_token = new_token_getter.fetchToken()
return FetchTwilioToken(new_token=new_token)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment