示例#1
0
文件: schema.py 项目: wapiflapi/gqles
import json
import uuid

import ariadne

import eventsourcing.utils.topic
import eventsourcing.application.notificationlog

import sqlalchemy

from gqles.application import get_system_runner
import gqles.scalars

state_insight = ariadne.InterfaceType("StateInsight")

query = ariadne.ObjectType("Query")
application = ariadne.ObjectType("Application")
originator = ariadne.ObjectType("Originator")
insight = ariadne.ObjectType("Insight")
event = ariadne.ObjectType("Event")

types = [
    *gqles.scalars.types,
    query,
    application,
    originator,
    event,
    state_insight,
    insight,
]
示例#2
0
    def __init__(self):
        """
        The schema generator generates a GraphQL schema.
        The purpose is to provide a schema to which resolvers are then
        attached, which is then given to Ariadne, and for resolvers to
        have information about expected types.

        For RPSL queries and types, this is dynamically generated based on
        the RPSL objects from irrd.rpsl. Other parts are fixed.
        This means that the schema is always the same for a given IRRd
        codebase - there are no runtime or user configurable parts.

        Along with generating the schema, some metadata is saved, e.g.
        self.graphql_types which allows resolvers to learn the GraphQL
        type for a certain field.

        This generator also creates Ariadne object types on self, which
        are used to attach resolvers to them.
        """
        self._set_rpsl_query_fields()
        self._set_rpsl_object_interface_schema()
        self._set_rpsl_contact_schema()
        self._set_rpsl_object_schemas()
        self._set_enums()

        schema = self.enums
        schema += """
            scalar ASN
            scalar IP

            schema {
              query: Query
            }

            type Query {
              rpslObjects(""" + self.rpsl_query_fields + """): [RPSLObject!]
              databaseStatus(sources: [String!]): [DatabaseStatus]
              asnPrefixes(asns: [ASN!]!, ipVersion: Int, sources: [String!]): [ASNPrefixes!]
              asSetPrefixes(setNames: [String!]!, ipVersion: Int, sources: [String!], excludeSets: [String!], sqlTrace: Boolean): [AsSetPrefixes!]
              recursiveSetMembers(setNames: [String!]!, depth: Int, sources: [String!], excludeSets: [String!], sqlTrace: Boolean): [SetMembers!]
            }

            type DatabaseStatus {
                source: String!
                authoritative: Boolean!
                objectClassFilter: [String!]
                rpkiRovFilter: Boolean!
                scopefilterEnabled: Boolean!
                localJournalKept: Boolean!
                serialOldestJournal: Int
                serialNewestJournal: Int
                serialLastExport: Int
                serialNewestMirror: Int
                lastUpdate: String
                synchronisedSerials: Boolean!
            }

            type RPSLJournalEntry {
                rpslPk: String!
                source: String!
                serialNrtm: Int!
                operation: String!
                origin: String
                objectClass: String!
                objectText: String!
                timestamp: String!
            }

            type ASNPrefixes {
                asn: ASN!
                prefixes: [IP!]
            }

            type AsSetPrefixes {
                rpslPk: String!
                prefixes: [IP!]
            }

            type SetMembers {
                rpslPk: String!
                rootSource: String!
                members: [String!]
            }
        """
        schema += self.rpsl_object_interface_schema
        schema += self.rpsl_contact_schema
        schema += ''.join(self.rpsl_object_schemas.values())
        schema += 'union RPSLContactUnion = RPSLPerson | RPSLRole'

        self.type_defs = ariadne.gql(schema)

        self.query_type = ariadne.QueryType()
        self.rpsl_object_type = ariadne.InterfaceType("RPSLObject")
        self.rpsl_contact_union_type = ariadne.UnionType("RPSLContactUnion")
        self.asn_scalar_type = ariadne.ScalarType("ASN")
        self.ip_scalar_type = ariadne.ScalarType("IP")
        self.object_types = [
            self.query_type, self.rpsl_object_type,
            self.rpsl_contact_union_type, self.asn_scalar_type,
            self.ip_scalar_type
        ]

        for name in self.rpsl_object_schemas.keys():
            self.object_types.append(ariadne.ObjectType(name))

        self.object_types.append(ariadne.ObjectType("ASNPrefixes"))
        self.object_types.append(ariadne.ObjectType("AsSetPrefixes"))
        self.object_types.append(ariadne.ObjectType("SetMembers"))
        self.object_types.append(ariadne.EnumType("RPKIStatus", RPKIStatus))
        self.object_types.append(
            ariadne.EnumType("ScopeFilterStatus", ScopeFilterStatus))
示例#3
0
文件: server.py 项目: wl44545/al
    todo = {"id": str(uuid.uuid4()), "name": name}
    todos.append(todo)
    return {"success": True, "todo": todo}


@ariadne.convert_kwargs_to_snake_case
def resolve_delete_todo(obj, info, todo_id):
    for i, todo in enumerate(todos):
        print(todo_id, todo["id"])
        if todo["id"] == todo_id:
            del todos[i]
            return {"success": True}
    return {"success": False, "errors": ["Can't find todo"]}


query = ariadne.ObjectType("Query")
query.set_field("todos", resolve_todos)
query.set_field("todo", resolve_todo)

mutation = ariadne.ObjectType("Mutation")
mutation.set_field("createTodo", resolve_create_todo)
mutation.set_field("deleteTodo", resolve_delete_todo)

schema = ariadne.make_executable_schema(
    ariadne.load_schema_from_path("schema.graphql"), query, mutation,
    ariadne.snake_case_fallback_resolvers)


@app.route("/graphql", methods=["GET"])
def graphql_playground():
    data = request.args.get("query")
#!/usr/bin/env python3
import datetime
import unicodedata
import ariadne
import re
from .const import COMMENT as CT, PARTY_ALIAS as PA
from .db_conn import get_db_conn

comment_pattern = re.compile(r"<C>\d{16}<\/C>")
comment_pattern_blank = re.compile(r" <C>\d{16}<\/C>")

query_resolver = ariadne.ObjectType("Query")  # General query
talk_resolver = ariadne.ObjectType("Talk")  # For talk argument filed
mp_resolver = ariadne.ObjectType("MP")  # For talks filed
session_resolver = ariadne.ObjectType("Session")  # For talks field
date_scalar = ariadne.ScalarType("Date")  # Date de-seralise


@query_resolver.field('getMissing')
@session_resolver.field('missing')
def getMissingMPs(obj,
                  info,
                  session_id=None,
                  date=None,
                  mp_id=None,
                  mp_name=None,
                  party=None):
    query = 'SELECT distinct m.resid, m.f_name, m.s_name, role, party FROM parliaments p join missing m on p.resid = m.resid JOIN head h on h.headid = m.sessionid WHERE '
    params = []

    if obj: