Пример #1
0
 public GraphQLVisitor(ISchemaProvider schemaProvider, IMethodProvider methodProvider, QueryVariables variables, ClaimsIdentity claims)
 {
     this.claims         = claims;
     this.schemaProvider = schemaProvider;
     this.methodProvider = methodProvider;
     this.variables      = variables;
 }
Пример #2
0
 public WhatToDoNext DoGetBuildDir(string basis)
 {
     query_mode  = true;
     query_var   = QueryVariables.BuildDir;
     query_basis = basis;
     return(Check(SetMajorMode("variable query") || SetOperation("variable query")));
 }
Пример #3
0
 public WhatToDoNext DoGetTopSrcDir()
 {
     query_mode  = true;
     query_var   = QueryVariables.SrcDir;
     query_basis = "/";
     return(Check(SetMajorMode("variable query") || SetOperation("variable query")));
 }
Пример #4
0
        private async Task SaveMediaList(PlexPayload payload, Media anime)
        {
            var mutation  = @"
            mutation($mediaId: Int, $status: MediaListStatus, $progress: Int, $score: Float, $startedAt: FuzzyDateInput, $completedAt: FuzzyDateInput){ 
                SaveMediaListEntry (mediaId: $mediaId, status: $status, progress: $progress, score: $score, startedAt: $startedAt, completedAt: $completedAt)
                { 
                    id 
                    status 
                } 
            }
            ";
            var variables = new QueryVariables();

            variables.MediaId = anime.Id;

            if (!string.IsNullOrEmpty(payload.Rating))
            {
                variables.Score = int.Parse(payload.Rating);
            }
            else
            {
                var isMovie     = payload.Metadata.Type == "movie";
                var isCompleted = isMovie ? true : payload.Metadata.Index == anime.Episodes;

                variables.Status = isCompleted ? MediaListStatus.COMPLETED : MediaListStatus.CURRENT;
                if (!isCompleted)
                {
                    variables.Progress = payload.Metadata.Index;
                }
            }

            var queryBody = new QueryBody(mutation, variables);

            await QueryAnilist(queryBody);
        }
Пример #5
0
        private async Task <MediaList> SearchMediaList(int userId, Media anime)
        {
            var query     = @"
            query($userId: Int, $mediaId: Int){
                Page (page: 1, perPage: 50) {
                    pageInfo {
                        total
                        currentPage
                        lastPage
                        hasNextPage
                        perPage
                    }
                    mediaList(userId: $userId, mediaId : $mediaId, type:ANIME){
                        id
                        status
                    }
                }
            }
            ";
            var variables = new QueryVariables
            {
                UserId  = userId,
                MediaId = anime.Id
            };
            var queryBody = new QueryBody(query, variables);

            var responseData = await QueryAnilist(queryBody);

            var anilistReturnData = AnlistReturnData.FromJson(responseData);

            return(anilistReturnData.Data.Page?.MediaList?.FirstOrDefault());
        }
 public QueryGrammerNodeVisitor(Expression expression, ISchemaProvider schemaProvider, IMethodProvider methodProvider, QueryVariables variables)
 {
     currentContext      = (ExpressionResult)expression;
     this.schemaProvider = schemaProvider;
     this.methodProvider = methodProvider;
     this.variables      = variables;
 }
 public OperationVisitor(QueryVariables variables, Schema.ISchemaProvider schemaProvider, ClaimsIdentity claims)
 {
     this.claims         = claims;
     this.variables      = variables;
     this.schemaProvider = schemaProvider;
     this.operation      = new GraphQLOperation();
 }
Пример #8
0
 public EntityQueryNodeVisitor(Expression expression, ISchemaProvider schemaProvider, IMethodProvider methodProvider, QueryVariables variables, ClaimsIdentity claims)
 {
     this.claims         = claims;
     currentContext      = (ExpressionResult)expression;
     this.schemaProvider = schemaProvider;
     this.methodProvider = methodProvider;
     this.variables      = variables;
 }
Пример #9
0
 /// Parses a GraphQL-like query syntax into a tree respresenting the requested object graph. E.g.
 /// {
 ///   entity/query {
 ///     field1,
 ///     field2,
 ///     relation { field }
 ///   },
 ///   ...
 /// }
 ///
 /// The returned DataQueryNode is a root node, it's Fields are the top level data queries
 public GraphQLResultNode Compile(string query, QueryVariables variables = null)
 {
     if (variables == null)
     {
         variables = new QueryVariables();
     }
     return(Compile(new QueryRequest {
         Query = query, Variables = variables
     }));
 }
Пример #10
0
        private string GetLabelQuery(string orginaztionName, string repoPage)
        {
            var labelQuery = FormatQuery(query);

            var variables = new QueryVariables(orginaztionName, repoPage);

            var variablesAsString = stringSerializer.Serialize(variables);

            var body = $"{{\"query\":\"{labelQuery}\",\"variables\":{variablesAsString}}}";

            return(body);
        }
Пример #11
0
        private string GetLabelQuery(string owner, string repository, string pageId)
        {
            var labelQuery = FormatQuery(queryText);

            var variables = new QueryVariables(owner, repository, pageId);

            var variablesAsString = stringSerializer.Serialize(variables);

            var body = $"{{\"query\":\"{labelQuery}\",\"variables\":{variablesAsString}}}";

            return(body);
        }
Пример #12
0
        public static CompiledQueryResult CompileWith(string query, Expression context, ISchemaProvider schemaProvider, IMethodProvider methodProvider = null, QueryVariables variables = null)
        {
            if (methodProvider == null)
            {
                methodProvider = new DefaultMethodProvider();
            }
            if (variables == null)
            {
                variables = new QueryVariables();
            }
            var expression = CompileQuery(query, context, schemaProvider, methodProvider, variables);

            var parameters = expression.Expression.NodeType == ExpressionType.Lambda ? ((LambdaExpression)expression.Expression).Parameters.ToList() : new List<ParameterExpression>();
            return new CompiledQueryResult(expression, parameters);
        }
Пример #13
0
        private async Task <Media> SearchAnilist(PlexPayload payload)
        {
            var query = @"
            query($search:String, $seasonYear: Int, $format: MediaFormat){
                Page (page: 1, perPage: 1) {
                    pageInfo {
                    total
                    currentPage
                    lastPage
                    hasNextPage
                    perPage
                    }
                    media(search:$search, seasonYear:$seasonYear, format: $format, type:ANIME){
                    id
                    title {
                        romaji
                    }
                    episodes
                    }
                }
            }
            ";

            if (string.IsNullOrEmpty(payload.Metadata.GrandparentTitle))
            {
                payload.Metadata.GrandparentTitle = null;
            }

            var variables = new QueryVariables
            {
                Search     = payload.Metadata.GrandparentTitle ?? payload.Metadata.ParentTitle ?? payload.Metadata.Title,
                SeasonYear = payload.Metadata.Year,
                Format     = payload.Metadata.Type == "movie" ? MediaFormat.MOVIE : MediaFormat.TV
            };
            var queryBody = new QueryBody(query, variables);

            var responseData = await QueryAnilist(queryBody);

            var anilistReturnData = AnlistReturnData.FromJson(responseData);

            return(anilistReturnData.Data.Page?.Media?.FirstOrDefault());
        }
Пример #14
0
 public OperationVisitor(QueryVariables variables, Schema.ISchemaProvider schemaProvider)
 {
     this.variables       = variables;
     this.operation       = new GraphQLOperation();
     this.constantVisitor = new ConstantVisitor(schemaProvider);
 }
Пример #15
0
 public OperationVisitor(QueryVariables variables)
 {
     this.variables = variables;
     this.operation = new GraphQLOperation();
 }
Пример #16
0
        private static ExpressionResult CompileQuery(string query, Expression context, ISchemaProvider schemaProvider, ClaimsIdentity claims, IMethodProvider methodProvider, QueryVariables variables)
        {
            AntlrInputStream stream = new AntlrInputStream(query);
            var lexer  = new EntityGraphQLLexer(stream);
            var tokens = new CommonTokenStream(lexer);
            var parser = new EntityGraphQLParser(tokens)
            {
                BuildParseTree = true
            };
            var tree = parser.startRule();

            var visitor    = new QueryGrammerNodeVisitor(context, schemaProvider, methodProvider, variables, claims);
            var expression = visitor.Visit(tree);

            return(expression);
        }
Пример #17
0
        /// <summary>
        /// Compile a query.
        /// </summary>
        /// <param name="query">The query text</param>
        /// <param name="schemaProvider"></param>
        /// <param name="methodProvider"></param>
        /// <returns></returns>
        public static CompiledQueryResult Compile(string query, ISchemaProvider schemaProvider, ClaimsIdentity claims, IMethodProvider methodProvider, QueryVariables variables)
        {
            ParameterExpression contextParam = null;

            if (schemaProvider != null)
            {
                contextParam = Expression.Parameter(schemaProvider.ContextType);
            }
            var expression = CompileQuery(query, contextParam, schemaProvider, claims, methodProvider, variables);

            var contextParams = new List <ParameterExpression>();

            if (contextParam != null)
            {
                contextParams.Add(contextParam);
            }
            return(new CompiledQueryResult(expression, contextParams));
        }
Пример #18
0
        public static QueryResult CompileWith(string query, Expression context, ISchemaProvider schemaProvider, IMethodProvider methodProvider, QueryVariables variables)
        {
            var expression = CompileQuery(query, context, schemaProvider, methodProvider, variables);

            var parameters = expression.Expression.NodeType == ExpressionType.Lambda ? ((LambdaExpression)expression.Expression).Parameters.ToList() : new List <ParameterExpression>();

            if (expression.ConstantParameters != null)
            {
                parameters.AddRange(expression.ConstantParameters.Keys);
            }
            return(new QueryResult(expression, parameters, expression.ConstantParameters?.Values));
        }
Пример #19
0
        /// <summary>
        /// Compile a query.
        /// </summary>
        /// <param name="query">The query text</param>
        /// <param name="schemaProvider"></param>
        /// <param name="methodProvider"></param>
        /// <returns></returns>
        public static QueryResult Compile(string query, ISchemaProvider schemaProvider, IMethodProvider methodProvider, QueryVariables variables)
        {
            ParameterExpression contextParam = null;

            if (schemaProvider != null)
            {
                contextParam = Expression.Parameter(schemaProvider.ContextType);
            }
            var expression = CompileQuery(query, contextParam, schemaProvider, methodProvider, variables);

            var contextParams = new List <ParameterExpression>();

            if (contextParam != null)
            {
                contextParams.Add(contextParam);
            }
            if (expression.ConstantParameters.Any())
            {
                contextParams.AddRange(expression.ConstantParameters.Keys);
            }
            return(new QueryResult(expression, contextParams, expression.ConstantParameters.Values));
        }
Пример #20
0
 public QueryBody(string query, QueryVariables variables = null)
 {
     Query     = query;
     Variables = variables;
 }
Пример #21
0
	public WhatToDoNext DoGetTopSrcDir () {
		query_mode = true;
		query_var = QueryVariables.SrcDir;
		query_basis = "/";
		return Check (SetMajorMode ("variable query") || SetOperation ("variable query"));
	}
Пример #22
0
 public GraphQLVisitor(ISchemaProvider schemaProvider, IMethodProvider methodProvider, QueryVariables variables)
 {
     this.schemaProvider = schemaProvider;
     this.methodProvider = methodProvider;
     this.variables      = variables;
 }
Пример #23
0
 public OperationVisitor(QueryVariables variables, Schema.ISchemaProvider schemaProvider)
 {
     this.variables      = variables;
     this.schemaProvider = schemaProvider;
     this.operation      = new GraphQLOperation();
 }
Пример #24
0
	public WhatToDoNext DoGetBuildDir (string basis) {
		query_mode = true;
		query_var = QueryVariables.BuildDir;
		query_basis = basis;
		return Check (SetMajorMode ("variable query") || SetOperation ("variable query"));
	}