示例#1
0
        TranslationQueries,
        WarehouseQueries,
        WebhookQueries,
):
    pass


class Mutation(
        AccountMutations,
        CheckoutMutations,
        CoreMutations,
        DiscountMutations,
        ExtensionsMutations,
        GiftCardMutations,
        MenuMutations,
        OrderMutations,
        PageMutations,
        PaymentMutations,
        ProductMutations,
        ShippingMutations,
        ShopMutations,
        StockMutations,
        WarehouseMutations,
        WebhookMutations,
        WishlistMutations,
):
    pass


schema = build_schema(Query, mutation=Mutation)
示例#2
0
import graphene
from graphene_federation import build_schema

import profiles.schema
import services.schema
import subscriptions.schema
import youths.schema


class Query(
        profiles.schema.Query,
        youths.schema.Query,
        subscriptions.schema.Query,
        graphene.ObjectType,
):
    pass


class Mutation(
        profiles.schema.Mutation,
        services.schema.Mutation,
        subscriptions.schema.Mutation,
        youths.schema.Mutation,
        graphene.ObjectType,
):
    pass


schema = build_schema(Query, Mutation)
示例#3
0
文件: api.py 项目: sbaisden25/saleor

class Mutation(
        AccountMutations,
        AppMutations,
        AttributeMutations,
        ChannelMutations,
        CheckoutMutations,
        CoreMutations,
        CsvMutations,
        DiscountMutations,
        ExternalNotificationMutations,
        PluginsMutations,
        GiftCardMutations,
        InvoiceMutations,
        MenuMutations,
        MetaMutations,
        OrderMutations,
        PageMutations,
        PaymentMutations,
        ProductMutations,
        ShippingMutations,
        ShopMutations,
        WarehouseMutations,
        WebhookMutations,
):
    pass


schema = build_schema(Query, mutation=Mutation, types=unit_enums)
class Query(graphene.ObjectType):
    user = graphene.Field(User, username=graphene.String(required=True), required=True)
    users = graphene.List(User, required=True)

    def resolve_user(root, info, username):
        with open('../db/db.json', 'r') as file:
            db = json.load(file)
        user = next((u for u in db['users'] if u['username'] == username), None)
        return User(
            id=user['id'],
            username=user['username'],
            first_name=user['firstName'],
            last_name=user['lastName'],
            email=user['email']
        )

    def resolve_users(root, info):
        with open('../db/db.json', 'r') as file:
            db = json.load(file)
        return [
            User(
                id=user['id'],
                username=user['username'],
                first_name=user['firstName'],
                last_name=user['lastName'],
                email=user['email']
            ) for user in db['users']
        ]

schema = build_schema(query=Query)
示例#5
0
from graphene_federation import build_schema

from .account.schema import AuthMutations  #AccountMutations, AccountQueries, AuthMutations
# from .core.schema import CoreMutations, CoreQueries
# from .order.schema import OrderMutations, OrderQueries
from graphql_auth.schema import UserQuery, MeQuery


class Query(
        # AccountQueries,
        # CoreQueries,
        MeQuery,
        # OrderQueries,
        UserQuery,
):
    pass


class Mutation(
        AuthMutations,
        # AccountMutations,
        # CoreMutations,
        # OrderMutations,
):
    pass


schema = build_schema(query=Query, mutation=Mutation)
示例#6
0
import graphene
from polls.schema import Query as polls_schema_query

# Added this line for federation
from graphene_federation import build_schema


class Query(polls_schema_query):
    # This class will inherit from multiple Queries
    # as we begin to add more apps to our project
    pass


# Replaced the following line
# schema = graphene.Schema(query=Query)
schema = build_schema(Query)

introspection_dict = schema.introspect()
示例#7
0
def build_federated_schema(query=None, mutation=None, **kwargs):
    schema = build_schema(query, mutation, **kwargs)
    set_entity_resolver(schema)
    set_entity_type_resolver(schema)
    return schema
示例#8
0
@key(fields='id')
class FunnyText(ObjectType):
    class Meta:
        interfaces = (TextInterface, )

    def __resolve_reference(self, info, **kwargs):
        return FunnyText(id=self.id, body=f'funny_text_{self.id}')


@key(fields='id')
class FileNode(ObjectType):
    id = Int(required=True)
    name = String(required=True)

    def __resolve_reference(self, info, **kwargs):
        # todo test raise exception here
        return FileNode(id=self.id, name=f'file_{self.id}')


# to test that @key applied only to FileNode, but not to FileNodeAnother
class FileNodeAnother(ObjectType):
    id = Int(required=True)
    name = String(required=True)


class Query(ObjectType):
    file = Field(lambda: FileNode)


schema = build_schema(Query, types=[FileNode, FunnyText, FileNodeAnother])
示例#9
0
        return User(id=user_id, primary_email=self.primary_email)


# to test that @key applied only to FileNode, but not to FileNodeAnother
class FileNodeAnother(ObjectType):
    id = Int(required=True)
    name = String(required=True)


class FunnyMutation(Mutation):
    result = String(required=True)

    @classmethod
    def mutate(cls, root, info, **data):
        return FunnyMutation(result='Funny')


class Mutation(ObjectType):
    funny_mutation = FunnyMutation.Field()


types = [
    FileNode,
    FunnyText,
    FileNodeAnother,
    User
]

schema = build_schema(mutation=Mutation, types=types)
示例#10
0

class Post(ObjectType):
    id = Int(required=True)
    title = String(required=True)
    text = Field(lambda: FunnyText)
    files = List(NonNull(FileNode))
    author = Field(lambda: User)


class Query(ObjectType):
    goodbye = String()
    posts = List(NonNull(Post))

    def resolve_posts(root, info):
        return [
            Post(id=1, title='title1', text=FunnyText(id=1), files=[FileNode(id=1)]),
            Post(id=2, title='title2', text=FunnyText(id=2), files=[FileNode(id=2), FileNode(id=3)]),
            Post(id=3, title='title3', text=FunnyText(id=3)),
            Post(
                id=4, title='title4', text=FunnyText(id=4),
                author=User(primaryEmail="*****@*****.**")
            ),
        ]

    def resolve_goodbye(root, info):
        return 'See ya!'


schema = build_schema(query=Query, types=[FunnyTextAnother], auto_camelcase=False)
示例#11
0

# define a query
class Query(graphene.ObjectType):
    users = graphene.Field(User)

    def resolve_users(self, info, **kwargs):
        return UserModel.objects.all()


# define a mutation
class CreateUser(graphene.Mutation):
    user = graphene.Field(User)

    class Arguments:
        username = graphene.String()
        age = graphene.Int()

    def mutate(self, info, username, age):
        user = UserModel(username=username, age=age)
        user.save()
        return CreateUser(user)


class Mutation(graphene.ObjectType):
    create_user = CreateUser.Field()


# build schema USE THE FEDERATION PACKAGE
schema = build_schema(Query, types=[User], mutation=Mutation)
示例#12
0
class TextInterface(Interface):
    id = Int(required=True)
    body = String(required=True)


@key(fields='id')
class FunnyText(ObjectType):
    class Meta:
        interfaces = (TextInterface, )

    def __resolve_reference(self, info, **kwargs):
        return FunnyText(id=self.id, body=f'funny_text_{self.id}')


@key(fields='id')
class FileNode(ObjectType):
    id = Int(required=True)
    name = String(required=True)

    def __resolve_reference(self, info, **kwargs):
        # todo test raise exception here
        return FileNode(id=self.id, name=f'file_{self.id}')


class Query(ObjectType):
    file = Field(lambda: FileNode)


schema = build_schema(Query, types=[FileNode, FunnyText])
示例#13
0
    securities = List(NonNull(Security), tickers=List(String, required=True))

    def resolve_securities(self, info, tickers):
        print(
            f"resolving_securities: self: {self}   info: {info}    tickers: {tickers}"
        )
        results = []
        for t in tickers:
            stock = STOCKS.get(t, None)
            if stock:
                results.append(stock)
        print(results)
        return results


schema = build_schema(query=Query, types=[Security], auto_camelcase=False)
print(schema)

app = Flask(__name__)
app.debug = True

app.add_url_rule('/graphql',
                 view_func=GraphQLView.as_view('graphql',
                                               schema=schema,
                                               graphiql=True))

if __name__ == '__main__':
    STOCKS = {
        'GOOG':
        Security(ticker='GOOG',
                 industry=Industry(sector='Information Technology')),
示例#14
0
from graphene import ObjectType, String, Int, Field
from graphene_federation import build_schema, key


@key(fields='id')
class FileNode(ObjectType):
    id = Int(required=True)
    name = String(required=True)

    def __resolve_reference(self, info, **kwargs):
        # todo test raise exception here
        return FileNode(id=self.id, name=f'file_{self.id}')


class Query(ObjectType):
    # todo support query w/o root fields
    file = Field(lambda: FileNode)


schema = build_schema(Query, types=[FileNode])
        leases.schema.Query,
        payments.schema.Query,
        resources.schema.Query,
        django_ilmoitin_schema.Query,
        graphene.ObjectType,
):
    @staticmethod
    @view_permission_required(NotificationTemplate)
    def resolve_notification_templates(parent, info, **kwargs):
        return django_ilmoitin_schema.Query.resolve_notification_templates(
            parent, info, **kwargs)


class Mutation(
        applications.schema.Mutation,
        contracts.schema.Mutation,
        customers.schema.Mutation,
        leases.schema.Mutation,
        payments.schema.Mutation,
        resources.schema.Mutation,
        graphene.ObjectType,
):
    pass


# We need to list all the extended types separately,
# otherwise graphene will not generate their schemas.
extended_types = [customers.schema.ProfileNode]

schema = build_schema(query=Query, mutation=Mutation, types=extended_types)
示例#16
0
class Query(ObjectType):
    industries = List(NonNull(Industry), sector=List(String, required=True))

    def resolve_industries(self, info, sector):
        print(
            f"we're resolving: self: {self}   info: {info}    sector: {sector}"
        )
        results = []
        for i in sector:
            industry = INDUSTRIES.get(i, None)
            if industry:
                results.append(industry)
        return results


schema = build_schema(query=Query, types=[Industry], auto_camelcase=False)
print(schema)

app = Flask(__name__)
app.debug = True

app.add_url_rule('/graphql',
                 view_func=GraphQLView.as_view('graphql',
                                               schema=schema,
                                               graphiql=True))

if __name__ == '__main__':
    INDUSTRIES = {
        i.strip(): Industry(id=e, sector=i.strip())
        for e, i in enumerate("""Energy
        Materials