コード例 #1
0
    public static IPreparedOperation Compile(
        string operationId,
        DocumentNode document,
        OperationDefinitionNode operation,
        ISchema schema,
        ObjectType rootType,
        InputParser inputParser,
        IEnumerable <ISelectionOptimizer>?optimizers = null)
    {
        if (operationId == null)
        {
            throw new ArgumentNullException(nameof(operationId));
        }

        if (document == null)
        {
            throw new ArgumentNullException(nameof(document));
        }

        if (operation == null)
        {
            throw new ArgumentNullException(nameof(operation));
        }

        if (schema == null)
        {
            throw new ArgumentNullException(nameof(schema));
        }

        if (rootType == null)
        {
            throw new ArgumentNullException(nameof(rootType));
        }

        if (operation.SelectionSet.Selections.Count == 0)
        {
            throw OperationCompiler_NoOperationSelections(operation);
        }

        var fragments          = new FragmentCollection(schema, document);
        var compiler           = new OperationCompiler(schema, fragments, inputParser);
        var selectionSetLookup = new Dictionary <SelectionSetNode, SelectionVariants>();
        var backlog            = new Stack <CompilerContext>();

        // creates and enqueues the root compiler context.
        CompilerContext.New(
            backlog,
            rootType,
            operation.SelectionSet,
            optimizers?.ToImmutableList() ?? ImmutableList <ISelectionOptimizer> .Empty,
            selectionSetLookup);

        // processes the backlog and by doing so traverses the query graph.
        compiler.Visit(backlog);

        return(new Operation(operationId, document, operation, rootType, selectionSetLookup));
    }
コード例 #2
0
ファイル: Fragment.cs プロジェクト: dekkerb115/Bam.Net
 public ActionResult Save(Bam.Net.Analytics.Fragment[] values)
 {
     try
     {
         FragmentCollection saver = new FragmentCollection();
         saver.AddRange(values);
         saver.Save();
         return(Json(new { Success = true, Message = "", Dao = "" }));
     }
     catch (Exception ex)
     {
         return(GetErrorResult(ex));
     }
 }
コード例 #3
0
        public FieldCollectorBenchmarks()
        {
            var resources = new ResourceHelper();

            _schema = SchemaBuilder.New().AddStarWarsTypes().Create();

            _introspectionQuery = Utf8GraphQLParser.Parse(
                resources.GetResourceString("IntrospectionQuery.graphql"));
            _introspectionFragments = new FragmentCollection(_schema, _introspectionQuery);
            _introspectionOperation = (OperationDefinitionNode)_introspectionQuery.Definitions[0];

            _starWarsQuery = Utf8GraphQLParser.Parse(
                resources.GetResourceString("GetTwoHerosWithFriendsQuery.graphql"));
            _starWarsFragments = new FragmentCollection(_schema, _starWarsQuery);
            _starWarsOperation = (OperationDefinitionNode)_starWarsQuery.Definitions[0];
        }
コード例 #4
0
    private FragmentCollection LocateCollection(string documentPath, bool throwIfMissing = true)
    {
        if (!documentCache.TryGetValue(documentPath, out FragmentCollection fragments))
        {
            var contentFile = fileLocator.Locate(documentPath, throwIfMissing);
            if (contentFile == null)
            {
                return(null);
            }
            DsonDocument root = DsonDocument.LoadFromFile(this, contentFile, documentPath);
            fragments = FragmentCollection.FillFrom(root);

            documentCache[documentPath] = fragments;
        }

        return(fragments);
    }
コード例 #5
0
    public DsonObject Locate(string url, bool throwIfMissing = true)
    {
        Uri                uri          = new Uri("scheme:" + url);
        string             documentPath = Uri.UnescapeDataString(uri.AbsolutePath);
        FragmentCollection fragments    = LocateCollection(documentPath, throwIfMissing);

        if (fragments == null)
        {
            return(null);
        }

        string     fragmentId = Uri.UnescapeDataString(uri.Fragment.Substring(1));
        DsonObject obj        = fragments.Locate(fragmentId);

        if (obj == null && throwIfMissing)
        {
            throw new InvalidOperationException("Couldn't locate fragment in document: " + url);
        }
        return(obj);
    }
コード例 #6
0
    public DsonDocument LocateRoot(string documentPath)
    {
        FragmentCollection fragments = LocateCollection(documentPath);

        return(fragments.Root);
    }
コード例 #7
0
 private OperationCompiler(ISchema schema, FragmentCollection fragments, InputParser parser)
 {
     _schema    = schema ?? throw new ArgumentNullException(nameof(schema));
     _fragments = fragments ?? throw new ArgumentNullException(nameof(fragments));
     _parser    = parser ?? throw new ArgumentNullException(nameof(parser));
 }