def test_scalar_serializer_can_be_set_with_setter():
    schema = build_schema(type_defs)
    scalar = ScalarType("DateInput")
    scalar.set_serializer(serialize_date)
    scalar.bind_to_schema(schema)

    schema_scalar = schema.type_map.get("DateInput")
    assert schema_scalar.serialize is serialize_date
Пример #2
0
# middleware

middleware = [
    Middleware(AuthenticationMiddleware, backend=TokenAuthenticationBackend())
]


# GraphQL

schema_path = (
    pathlib.Path(__file__).parent.absolute().joinpath("graphql", "schema.graphql")
)
type_defs = load_schema_from_path("saltapi/graphql/schema.graphql")

datetime_scalar = ScalarType("Datetime")
datetime_scalar.set_serializer(scalars.serialize_datetime)
datetime_scalar.set_value_parser(scalars.parse_datetime)

proposal_code_scalar = ScalarType("ProposalCode")
proposal_code_scalar.set_serializer(scalars.serialize_proposal_code)
proposal_code_scalar.set_value_parser(scalars.parse_proposal_code)

mutation = MutationType()
mutation.set_field("submitProposal", resolvers.resolve_submit_proposal)

subscription = SubscriptionType()
subscription.set_field("submissionProgress", resolvers.resolve_submission_progress)
subscription.set_source("submissionProgress", resolvers.submission_progress_generator)

schema = make_executable_schema(
    type_defs,
Пример #3
0
        for fld in resolvers['Object'][obj]:
            objType.set_field(fld, resolvers['Object'][obj][fld])
        all_resolvers.append(objType)

# Map resolver functions to Mutation fields using MutationType
if 'Mutation' in resolvers and len(resolvers['Mutation']) > 0:
    mutation = MutationType()
    for m in resolvers['Mutation']:
        mutation.set_field(m, resolvers['Mutation'][m])
    all_resolvers.append(mutation)

# Map resolver functions to custom scalars using ScalarType
if 'Scalar' in resolvers and len(resolvers['Scalar']) > 0:
    for scalar in resolvers['Scalar']:
        scalarType = ScalarType(scalar)
        scalarType.set_serializer(resolvers['Scalar'][scalar]['serializer'])
        scalarType.set_literal_parser(
            resolvers['Scalar'][scalar]['literal_parser'])
        scalarType.set_value_parser(
            resolvers['Scalar'][scalar]['value_parser'])
        all_resolvers.append(scalarType)

# Create executable GraphQL schema
schema = make_executable_schema(type_defs, all_resolvers)

# --- ASGI app

# Create an ASGI app using the schema, running in debug mode
# Set context with authenticated graphql client.
app = GraphQL(schema, debug=True, context_value={})