Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Email type #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions graphene/types/email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from __future__ import absolute_import


from graphql import Undefined
from graphql.language.ast import StringValueNode
import json
from .scalars import Scalar


class Email(Scalar):
"""
Allows use of a JSON String for input / output from the GraphQL schema.

Use of this type is *not recommended* as you lose the benefits of having a defined, static
schema (one of the key benefits of GraphQL).
"""

@staticmethod
def serialize(dt):
return json.dumps(dt)

@staticmethod
def parse_literal(node, _variables=None):
# email_validator
# https://pypi.org/project/email-validator/
# max_length=254 to be compliant with RFCs 3696 and 5321
if isinstance(node, StringValueNode):
try:
return json.loads(node.value)
except Exception as error:
raise ValueError(f"Badly formed JSONString: {str(error)}")
return Undefined

@staticmethod
def parse_value(value):
return json.loads(value)
Loading