Example #1
0
    async def pass_async(self, the_query: TypedGQL, variables: dict = {}, **kwargs):
        query_node = the_query.query
        try:
            async with self.async_session.post(self._graphql_endpoint, json={"query": query_node, "variables": variables}) as resp:

                if resp.status == 200:
                    result = await resp.json() 
                    logger.debug(f"Received Reply {result}")

                    if "errors" in result:
                        raise GraphQLException(f"Ward {self._graphql_endpoint}:" + str(result["errors"]))

                    return the_query.extract(result["data"])

                if resp.status == 400:
                    raise WardException(await resp.json())


                if resp.status == 403:
                    console.log("Auth token is expired trying to refresh")
                    raise TokenExpired("Token Expired Error")


                raise WardException(f"Unexpected statuscode {resp.status} {resp}")

        except:
            console.print_exception(show_locals=True)
            raise 
Example #2
0
def test_typed_query(password_client):

    from bergen.query import TypedGQL

    nana = TypedGQL(
        '''query Nodes{
        nodes {
            id
        }
    }''', Node).run(ward=password_client.main_ward)

    assert len(nana) >= 1, "Your Arnheim Instance seems to have no nodes?"
Example #3
0
    async def pass_async(self,
                         the_query: TypedGQL,
                         variables: dict = {},
                         **kwargs):
        query_node = gql(the_query.query)
        try:
            try:
                response = await self.async_transport.execute(
                    query_node, variable_values=variables)
            except Exception as e:
                console.print_exception(show_locals=True)
                raise TokenExpired(f"Token Expired {e}")

            if response.errors:
                raise GraphQLException(f"Ward {self._graphql_endpoint}:" +
                                       str(response.errors))

            return the_query.extract(response.data)

        except:
            console.print_exception(show_locals=True)
            raise
Example #4
0
from bergen.schema import DataModel
from bergen.query import TypedGQL

HOST_GQL = TypedGQL(
    """
    mutation Host($identifier: String!, $extenders: [String]){
        host(identifier: $identifier, extenders: $extenders){
            id
            identifier
            extenders
            point {
                inward
            }
        }
    }
""", DataModel)
Example #5
0
from bergen.queries.delayed.node import DETAIL_NODE_FR
from bergen.schema import Assignation, Node, Peasent, Template, Pod, Provision, Transcript, VartPod, Volunteer
from bergen.query import TypedGQL

# Peasent Constants

SERVE_GQL = TypedGQL(
    """
    mutation Serve($name: String!){
        serve(name: $name){
            id
            name
            
        }
    }
""", Peasent)

OFFER_GQL = TypedGQL(
    """
    mutation Offer($node: ID!, $params: GenericScalar!, $policy: GenericScalar!){
        offer(node: $node, params: $params, policy: $policy){
            id
            name
            policy 
        }
    }
""", Template)

ACCEPT_GQL = TypedGQL(
    """
    mutation Accept($template: ID!, $provision: String!){
Example #6
0
 def pass_async(self, gql: TypedGQL, variables: dict = {}):
     return gql.cls(**{})