class Query(ObjectType): node = Node.Field() user = Node.Field(UserType) question = Node.Field(QuestionType) answer = Node.Field(AnswerType) all_users = MongoengineConnectionField(UserType) all_questions = MongoengineConnectionField(QuestionType) all_answers = MongoengineConnectionField(AnswerType)
class MusicQuery(ObjectType): genre = Node.Field(GenreNode) genres = DjangoFilterConnectionField(GenreNode) label = Node.Field(LabelNode) labels = DjangoFilterConnectionField(LabelNode) artist = Node.Field(ArtistNode) artists = DjangoFilterConnectionField(ArtistNode) album = Node.Field(AlbumNode) albums = DjangoFilterConnectionField(AlbumNode)
class Query(ObjectType): reporter = Node.Field(ReporterNode, description='Retrieve a single Reporter node.') reporters = DjangoFilterConnectionField( ReporterNode, description='Return a connection of Reporter.') publication = Node.Field(PublicationNode, description='Retrieve a single Publication node.') publications = DjangoFilterConnectionField( PublicationNode, description='Return a connection of Publication.') article = Node.Field(ArticleNode, description='Retrieve a single Article node.') articles = DjangoFilterConnectionField( ArticleNode, description='Return a connection of Article.')
class Query(graphene.ObjectType): node = Node.Field() reporter = graphene.Field(ReporterNode) article = graphene.Field(ArticleNode) def resolve_reporter(self, *args, **kwargs): return Reporter(id=1, first_name='ABA', last_name='X')
class Query( form_schema.Query, workflow_schema.Query, data_source_schema.Query, graphene.ObjectType, ): node = Node.Field()
class Query(graphene.ObjectType): node = Node.Field() reporter = graphene.Field(ReporterNode) all_articles = SQLAlchemyConnectionField(ArticleNode.connection) def resolve_reporter(self, _info): return session.query(Reporter).first()
class Query(graphene.ObjectType): node = Node.Field() bikes = MongoengineConnectionField(BikeType) shop_list = graphene.List(ShopType) def resolve_shop_list(self, info): return Shop.objects.all()
def make_schema(connection_string: str, top_level_fields: list): """Make a graphQL schema from an existing SQL database Args: connection_string (str): Standard SQLAlchemy DB conn string top_level_fields (list): List of table names to have as the top-level types Returns: schema (graphene.Schema): Schema all ready to use Notes: Relies heavily on foreign keys to find relationships, so make sure you have them! """ base_class = automap_base() engine = create_engine(connection_string) base_class.prepare(engine, reflect=True) session = scoped_session( sessionmaker(autocommit=False, autoflush=False, bind=engine)) base_class.query = session.query_property() query_properties = {"node": Node.Field()} for (cls, model) in base_class.classes.items(): meta = type("Meta", (), {"model": model, "interfaces": (Node, )}) subclass = type(cls, (SQLAlchemyObjectType, ), {"Meta": meta}) if cls in top_level_fields: query_properties[cls] = SQLAlchemyConnectionField(subclass) Query = type("Query", (ObjectType, ), query_properties) return Schema(query=Query)
class Query(graphene.ObjectType): node = Node.Field() reporter = graphene.Field(ReporterNode) article = graphene.Field(ArticleNode) def resolve_reporter(self, info): return Reporter(id=1, first_name="ABA", last_name="X")
class Query(graphene.ObjectType): node = Node.Field() # required by Relay spec courses = graphene.List(Course, required=False, description='Returns all courses') course = graphene.Field( Course, id=graphene.ID(required=True), required=False, description='Returns course by id', ) # assignment = graphene.Field( # Assignment, # id=graphene.ID(required=True), # required=False, # description='Returns assignment by id', # ) def resolve_courses(self, info): return [c for c in COURSES] def resolve_course(self, info, id): object_type, object_id = from_global_id(id) if object_type != 'Course': raise graphql.GraphQLError('Bad course id') return [c for c in COURSES if c.id == object_id][0]
class Query(graphene.ObjectType): node = Node.Field() allAwss = MongoengineConnectionField(AWS) allAzures = MongoengineConnectionField(Azure) sortAWSByHost = MongoengineConnectionField(AWS) sortAzureByHost = MongoengineConnectionField(Azure) sortAWSByName = MongoengineConnectionField(AWS) sortAzureByName = MongoengineConnectionField(Azure) fetchAWSData = graphene.String() fetchAzureData = graphene.String() allAwsImages = MongoengineConnectionField(AWSImage) allAzureImages = MongoengineConnectionField(AzureImage) def resolve_sortAWSByHost(self, info, **args): return AwsModel.objects().order_by("-isFavorite", "host") def resolve_sortAzureByHost(self, info, **args): return AzureModel.objects().order_by("-isFavorite", "host") def resolve_sortAWSByName(self, info, **args): return AwsModel.objects().order_by("-isFavorite", "name") def resolve_sortAzureByName(self, info, **args): return AzureModel.objects().order_by("-isFavorite", "name") def resolve_fetchAWSData(self, info): init_aws() return "Success" def resolve_fetchAzureData(self, info): init_azure() return "Success"
class Query(UserProfileQuery, TransactionQuery, CategoryQuery, CategoryGroupQuery, DateRangeQuery, PeriodTotalQuery, CategoryTotalQuery, PeriodCategoryTotalQuery, CategoryPeriodTotalQuery, CategorySetPeriodTotalQuery, ObjectType): node = Node.Field() if settings.DEBUG: debug = Field(DjangoDebug, name='_debug')
class Query(graphene.ObjectType): node = Node.Field() all_employees = ConnectionField(EmployeeConnection) all_role = ConnectionField(RoleConnection) @staticmethod def resolve_all_employees(_, info, **args): return get_all_employee()
class Query(graphene.ObjectType): node = Node.Field() # required by Relay spec me = graphene.Field(User) def resolve_me(self, info, **kwargs): if info.context.user.is_authenticated: return info.context.user else: return None
class Query( form_schema.Query, workflow_schema.Query, data_source_schema.Query, graphene.ObjectType, ): node = Node.Field() if settings.DEBUG: debug = graphene.Field(DjangoDebug, name="_debug")
class Query(graphene.ObjectType): node = Node.Field() words = MongoengineConnectionField(Word) def resolve_words(self, info, entry=None): if entry: return list(WordModel.objects.filter(entry=entry)) return list(WordModel.objects.all())
class Query(ObjectType): auth_user = Field(AuthUserNode) nexus = Node.Field(NexusNode) all_nexus = DjangoFilterConnectionField(NexusNode) identity = Node.Field(IdentityNode) all_identities = DjangoFilterConnectionField(IdentityNode) post = Node.Field(PostNode) all_posts = DjangoFilterConnectionField( PostNode, order_by=['to', '-received_timestamp']) def resolve_auth_user(self, info, **kwargs): user = info.context.user print(user) if not user.is_authenticated: return None return user
class Query(ObjectType): node = Node.Field() all_persons = SQLAlchemyConnectionField( PersonConnection, sort=Argument(SortEnumPerson, default_value=utils.EnumValue('id_asc', PersonModel.id.asc()))) all_next_person = SQLAlchemyConnectionField(PersonsConnection, sort=None) all_email = SQLAlchemyConnectionField(EmailsConnection)
class Query(graphene.ObjectType): node = Node.Field() posts = SQLAlchemyConnectionField(PostConnection, idea_id=graphene.ID()) ideas = SQLAlchemyConnectionField(Idea) thematics = graphene.List(Thematic, identifier=graphene.String(required=True)) # agent_profiles = SQLAlchemyConnectionField(AgentProfile) def resolve_ideas(self, args, context, info): connection_type = info.return_type.graphene_type # this is IdeaConnection model = connection_type._meta.node._meta.model # this is models.Idea query = get_query(model, context) discussion_id = context.matchdict['discussion_id'] discussion = models.Discussion.get(discussion_id) root_idea_id = discussion.root_idea.id descendants_query = model.get_descendants_query(root_idea_id, inclusive=False) query = query.filter(model.id.in_(descendants_query)).filter( model.hidden == False).order_by(model.id) # pagination is done after that, no need to do it ourself return query def resolve_posts(self, args, context, info): connection_type = info.return_type.graphene_type # this is PostConnection model = connection_type._meta.node._meta.model # this is models.PostUnion discussion_id = context.matchdict['discussion_id'] idea_id = args.get('idea_id', None) if idea_id is not None: id_ = int(Node.from_global_id(idea_id)[1]) idea = models.Idea.get(id_) if idea.discussion_id != discussion_id: return None else: discussion = models.Discussion.get(discussion_id) idea = discussion.root_idea query = idea.get_related_posts_query().filter( model.publication_state == models.PublicationStates.PUBLISHED).order_by( desc(model.creation_date), model.id) # pagination is done after that, no need to do it ourself return query def resolve_thematics(self, args, context, info): identifier = args.get('identifier', None) model = Thematic._meta.model discussion_id = context.matchdict['discussion_id'] query = get_query( model, context).filter(model.discussion_id == discussion_id).filter( model.identifier == identifier).filter( model.hidden == False).filter( model.tombstone_date == None).order_by(model.id) return query
class LightPollutionQuery(graphene.ObjectType): light_p_ = Node.Field(LightPollutionType) light_p_list = MongoengineConnectionField(LightPollutionType) def resolve_light_p_list(self, info, **kwargs): if kwargs: return LightPollution.objects.filter(**kwargs) else: return LightPollution.objects.all()
class Query(ObjectType): node = Node.Field() user = Field(UserType, userid=ID(required=False, default_value=None)) users = List(UserType) def resolve_user(self, info, userid=None): return UserModel.objects(pk=userid).get() def resolve_users(self, info, userid=None): return list(UserModel.objects.all())
class Query(graphene.ObjectType): node = Node.Field() reporter = graphene.Field(ReporterNode) article = graphene.Field(ArticleNode) all_articles = PynamoConnectionField(ArticleNode) def resolve_reporter(self, *args, **kwargs): return next(Reporter.query(1)) def resolve_article(self, *args, **kwargs): return next(Article.query(1))
class Query(graphene.ObjectType): node = Node.Field() reporter = graphene.Field(ReporterNode) article = graphene.Field(ArticleNode) all_articles = SQLAlchemyConnectionField(ArticleNode) def resolve_reporter(self, *args, **kwargs): return Reporter(id=1, first_name='ABA', last_name='X') def resolve_article(self, *args, **kwargs): return Article(id=1, headline='Article node')
class Query(graphene.ObjectType): node = Node.Field() reporter = graphene.Field(ReporterNode) article = graphene.Field(ArticleNode) all_articles = SQLAlchemyConnectionField(ArticleNode) def resolve_reporter(self, *args, **kwargs): return session.query(Reporter).first() def resolve_article(self, *args, **kwargs): return session.query(Article).first()
class Query(graphene.ObjectType): node = Node.Field() articles = PynamoConnectionField(ArticleNode) def resolve_articles(self, *args, **kwargs): return [ Article(1, headline='One'), Article(2, headline='Two'), Article(3, headline='Three'), Article(4, headline='Four') ]
class Query(graphene.ObjectType): node = Node.Field() all_testers = MongoengineConnectionField(Tester) all_bugs = MongoengineConnectionField(Bugs) tester = graphene.Field(Tester) bugs = graphene.Field(Bugs) tester_devices = graphene.Field(TesterDevices) devices = graphene.Field(Devices) testers = graphene.List(Tester, uid=graphene.Int(), countries=graphene.List(graphene.String), country=graphene.String(), devices=graphene.List(graphene.String), rawquery=graphene.JSONString()) """ Method to resolve queries for testers by country and device I'm thinking there is an easier way of accomplishing this """ def resolve_testers(self, info, countries=["ALL"], uid=1, devices=["ALL"], rawquery=None): results = set() countries = list(map(lambda x: x.upper(), countries)) print(rawquery, type(rawquery)) # for this to work we will need to parse field types if rawquery is not None: return list(models.Tester.objects(__raw__=rawquery).all()) if not_none_or_all(countries): query_result = models.Tester.objects(country__in=countries).all() elif countries == ["ALL"]: query_result = models.Tester.objects.all() if query_result is not None: if not_none_or_all(devices): device_ids = list( map( lambda d: models.Devices.objects( description__icontains=d).first().id, devices)) for id in device_ids: for item in query_result.filter(devices=id): results.add(item) return list(results) elif devices == ["ALL"]: return list(query_result) return "error processing query"
class Query(graphene.ObjectType): node = Node.Field() GetProducts = graphene.List( Product, name=graphene.String(), code=graphene.Int(), cost=graphene.Int(), amount=graphene.Int(), ) def resolve_GetProducts(self, info, **kwargs): return list(ProductModel.objects.filter(**kwargs))
class Query(ObjectType): node = Node.Field() users = SQLAlchemyConnectionField(User) viewer = Field(User) post = Node.Field(Post) posts = SQLAlchemyConnectionField(Post, args={"query": String()}) tags = SQLAlchemyConnectionField(Tag) tag = Node.Field(Tag) categories = SQLAlchemyConnectionField(Category) category = Node.Field(Category) @staticmethod def resolve_viewer(root, _): """ Return the current viewer, if existed :param root: the root object :return: object represents current viewer, or None """ return root.get("viewer") @staticmethod def resolve_posts(_, info, **kwargs): """ Return the search based on query (or show them all) :param info: the info (context, etc.) on query :param kwargs: rest of the query :return: a list of post """ keyword = "%{}%".format(kwargs.get("query", "")) query = Post.get_query(info) return query.filter( or_(models.Post.title.like(keyword), models.Post.content.like(keyword), models.Post.excerpt.like(keyword))).all()
class Query(graphene.ObjectType): node = Node.Field() all_sentiment = MongoengineConnectionField(Sentiment) sentiment = graphene.Field(Sentiment, term=graphene.String(required=True)) def resolve_sentiment(parent, info, term): term = term.lower() sentiment = get_recent_sentiment_in_db(term) if sentiment is None: # No sentiment for this term found (or it was older than 15 minutes) add_sentiment(term) sentiment = get_recent_sentiment_in_db(term) return sentiment else: return sentiment
class Query(ObjectType): college = Node.Field(CollegeNode) career = Node.Field(CareerNode) city = Node.Field(CityNode) contact = Node.Field(ContactNode) monitor = Node.Field(MonitorNode) service = Node.Field(ServiceNode) skill = Node.Field(SkillNode) client = Node.Field(ClientNode) quoation = Node.Field(QuoationNode) all_colleges = DjangoFilterConnectionField(CollegeNode) all_careers = DjangoFilterConnectionField(CareerNode) all_cities = DjangoFilterConnectionField(CityNode) all_contacts = DjangoFilterConnectionField(ContactNode) all_monitors = DjangoFilterConnectionField(MonitorNode) all_services = DjangoFilterConnectionField(ServiceNode) all_skills = DjangoFilterConnectionField(SkillNode) all_clients = DjangoFilterConnectionField(ClientNode) all_quoations = DjangoFilterConnectionField(QuoationNode)