Ejemplo n.º 1
0
 static GraphLayoutSchema()
 {
     schema = new GraphSchema("GraphLayoutSchema");
     boundsProperty = schema.Properties.AddNewProperty("Bounds", typeof(System.Windows.Rect));
     labelBoundsProperty = Schema.Properties.AddNewProperty("LabelBounds", typeof(System.Windows.Rect));
     active = Schema.Categories.AddNewCategory("Active");
 }
Ejemplo n.º 2
0
 public GraphQLController(GraphSchema schema, AuthorSubscription author, IAuthor authorDetails)
 {
     _schema             = schema;
     _authorsubscription = author;
     _authorDetails      = authorDetails;
     //_schema.AddSubscription(author);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a graph link between the two specified pins
        /// </summary>
        /// <typeparam name="T">The type of the link. Should be GraphLink or one of its subclass</typeparam>
        /// <param name="output">The output pin from where the link originates</param>
        /// <param name="input">The input pin, where the link points to</param>
        /// <returns></returns>
        public static T CreateLink <T>(Graph graph, GraphPin output, GraphPin input) where T : GraphLink
        {
            // Make sure the pin types are correct
            if (output.PinType != GraphPinType.Output || input.PinType != GraphPinType.Input)
            {
                throw new System.ApplicationException("Invalid pin types while creating a link");
            }

            if (!GraphSchema.CanCreateLink(output, input))
            {
                return(null);
            }

            // Make sure a link doesn't already exists
            foreach (T link in graph.Links)
            {
                if (link.Input == input && link.Output == output)
                {
                    return(link);
                }
            }

            {
                Undo.RecordObject(graph, "Create Link");

                T link = CreateLink <T>(graph);
                link.Input  = input;
                link.Output = output;

                Undo.RegisterCreatedObjectUndo(link, "Create Link");
                return(link);
            }
        }
        public void Draw(GraphRendererContext rendererContext, GraphCamera camera)
        {
            if (!active)
            {
                return;
            }

            var mouseWorld = camera.ScreenToWorld(mouseScreenPosition);

            mousePin.Position = mouseWorld;


            GraphLinkRenderer.DrawGraphLink(rendererContext, link, camera);

            // Check the pin that comes under the mouse pin
            var targetPin = graphEditor.GetPinUnderPosition(mouseWorld);

            if (targetPin != null)
            {
                var sourcePin = attachedPin;
                var pins      = new GraphPin[] { sourcePin, targetPin };
                Array.Sort(pins, new GraphPinHierarchyComparer());
                string errorMessage;
                if (!GraphSchema.CanCreateLink(pins[0], pins[1], out errorMessage))
                {
                    GraphTooltip.message = errorMessage;
                }
            }
        }
        public void AddSingleQueryAction_AllDefaults_EnsureFieldStructure()
        {
            var schema = new GraphSchema() as ISchema;

            schema.SetNoAlterationConfiguration();
            var manager = new GraphSchemaManager(schema);

            manager.EnsureGraphType <SimpleMethodController>();

            var action = TemplateHelper.CreateFieldTemplate <SimpleMethodController>(nameof(SimpleMethodController.TestActionMethod));

            // query root exists, mutation does not (nothing was added to it)
            Assert.IsTrue(schema.OperationTypes.ContainsKey(GraphCollection.Query));
            Assert.IsFalse(schema.OperationTypes.ContainsKey(GraphCollection.Mutation));

            // field for the controller exists
            var topFieldName = nameof(SimpleMethodController).Replace(Constants.CommonSuffix.CONTROLLER_SUFFIX, string.Empty);

            Assert.IsTrue(schema.OperationTypes[GraphCollection.Query].Fields.ContainsKey(topFieldName));

            // ensure the field on the query is the right name (or throw)
            var topField = schema.OperationTypes[GraphCollection.Query][topFieldName];

            Assert.IsNotNull(topField);

            var type = schema.KnownTypes.FindGraphType(topField) as IObjectGraphType;

            // ensure the action was put into the field collection of the controller operation
            Assert.IsTrue(type.Fields.ContainsKey(action.Route.Name));
        }
        public void GeneralPropertyCheck_FromType()
        {
            var schema = new GraphSchema();
            var id     = new SubscriptionEventName(typeof(GraphSchema), "abc");

            Assert.AreEqual($"{schema.FullyQualifiedSchemaTypeName()}:abc", id.ToString());
            Assert.AreEqual($"{schema.FullyQualifiedSchemaTypeName()}:abc".GetHashCode(), id.GetHashCode());
        }
Ejemplo n.º 7
0
        public void DefaultFactory_UnknownTypeKInd_YieldsNoMaker()
        {
            var schema   = new GraphSchema();
            var factory  = new DefaultGraphTypeMakerProvider();
            var instance = factory.CreateTypeMaker(schema, TypeKind.LIST);

            Assert.IsNull(instance);
        }
Ejemplo n.º 8
0
        static RoslynGraphCategories()
        {
            Schema = RoslynGraphProperties.Schema;

            Overrides = Schema.Categories.AddNewCategory(
                "Overrides",
                () => new GraphMetadata(GraphMetadataOptions.Sharable));
        }
Ejemplo n.º 9
0
        static RoslynGraphCategories()
        {
            Schema = RoslynGraphProperties.Schema;

            Overrides = Schema.Categories.AddNewCategory(
                "Overrides",
                () => new GraphMetadata(GraphMetadataOptions.Sharable));
        }
 public void EnsureGraphType_DictionaryTK_ThrowsExeption()
 {
     Assert.Throws <GraphTypeDeclarationException>(() =>
     {
         var schema  = new GraphSchema() as ISchema;
         var manager = new GraphSchemaManager(schema);
         manager.EnsureGraphType(typeof(Dictionary <string, int>));
     });
 }
        public void EnsureGraphType_Enum_WithKindSupplied_IsAddedCorrectly()
        {
            var schema  = new GraphSchema() as ISchema;
            var manager = new GraphSchemaManager(schema);

            manager.EnsureGraphType(typeof(RandomEnum), TypeKind.ENUM);
            Assert.AreEqual(2, schema.KnownTypes.Count);  // added type + query
            Assert.IsTrue(schema.KnownTypes.Contains(typeof(RandomEnum), TypeKind.ENUM));
        }
        public void EnsureGraphType_Scalar_WithKindSupplied_IsAddedCorrectly()
        {
            var schema  = new GraphSchema() as ISchema;
            var manager = new GraphSchemaManager(schema);

            manager.EnsureGraphType(typeof(string), TypeKind.SCALAR);
            Assert.AreEqual(2, schema.KnownTypes.Count);  // added type + query
            Assert.IsTrue(schema.KnownTypes.Contains(typeof(string), TypeKind.SCALAR));
        }
Ejemplo n.º 13
0
        public void DefaultMetricsFactory_Create()
        {
            var schema  = new GraphSchema();
            var factory = new DefaultGraphQueryExecutionMetricsFactory <GraphSchema>(schema);

            var instance = factory.CreateMetricsPackage();

            Assert.IsNotNull(instance);
        }
        public void EnsureGraphType_Scalar_WithIncorrectKindSupplied_ThrowsException()
        {
            var schema  = new GraphSchema() as ISchema;
            var manager = new GraphSchemaManager(schema);

            Assert.Throws <GraphTypeDeclarationException>(() =>
            {
                manager.EnsureGraphType(typeof(string), TypeKind.ENUM);
            });
        }
        public void EnsureGraphType_Enum_WithIncorrectKindSupplied_ThrowsException()
        {
            var schema  = new GraphSchema() as ISchema;
            var manager = new GraphSchemaManager(schema);

            Assert.Throws <GraphTypeDeclarationException>(() =>
            {
                manager.EnsureGraphType(typeof(RandomEnum), TypeKind.SCALAR);
            });
        }
        public void EnsureGraphType_ListT_EndsWithTInGraphType()
        {
            var schema  = new GraphSchema() as ISchema;
            var manager = new GraphSchemaManager(schema);

            manager.EnsureGraphType(typeof(List <int>));

            Assert.AreEqual(2, schema.KnownTypes.Count);  // added type + query
            Assert.IsTrue(schema.KnownTypes.Contains(typeof(int)));
            Assert.IsTrue(schema.KnownTypes.Contains(Constants.ScalarNames.INT));
        }
        public void EnsureGraphType_Enum_WithIncorrectKindSupplied_ThatIsCoercable_AddsCorrectly()
        {
            var schema  = new GraphSchema() as ISchema;
            var manager = new GraphSchemaManager(schema);

            // object will be coerced to enum
            manager.EnsureGraphType(typeof(RandomEnum), TypeKind.OBJECT);
            Assert.AreEqual(2, schema.KnownTypes.Count);  // added type + query
            Assert.IsTrue(schema.KnownTypes.Contains(typeof(RandomEnum), TypeKind.ENUM));
            Assert.IsFalse(schema.KnownTypes.Contains(typeof(RandomEnum), TypeKind.OBJECT));
        }
        public void AddSingleQueryAction_NestedObjectsOnReturnType_EnsureAllTypesAreAdded()
        {
            var schema = new GraphSchema() as ISchema;

            schema.SetNoAlterationConfiguration();
            var manager = new GraphSchemaManager(schema);

            manager.EnsureGraphType <NestedMutationMethodController>();

            // mutation root exists and query exists (it must by definition even if blank)
            Assert.AreEqual(2, schema.OperationTypes.Count);
            Assert.IsTrue(schema.OperationTypes.ContainsKey(GraphCollection.Query));
            Assert.IsTrue(schema.OperationTypes.ContainsKey(GraphCollection.Mutation));

            // 5 distinct scalars (int, uint, float, decimal, string)
            Assert.AreEqual(5, schema.KnownTypes.Count(x => x.Kind == TypeKind.SCALAR));
            Assert.IsTrue(schema.KnownTypes.Contains(GraphQLProviders.ScalarProvider.RetrieveScalar(Constants.ScalarNames.STRING)));
            Assert.IsTrue(schema.KnownTypes.Contains(GraphQLProviders.ScalarProvider.RetrieveScalar(Constants.ScalarNames.INT)));
            Assert.IsTrue(schema.KnownTypes.Contains(GraphQLProviders.ScalarProvider.RetrieveScalar(Constants.ScalarNames.DECIMAL)));
            Assert.IsTrue(schema.KnownTypes.Contains(GraphQLProviders.ScalarProvider.RetrieveScalar(Constants.ScalarNames.FLOAT)));
            Assert.IsTrue(schema.KnownTypes.Contains(GraphQLProviders.ScalarProvider.RetrieveScalar(Constants.ScalarNames.UINT)));

            // 8 types
            // ----------------------
            //  mutation operation-type
            //  query operation-type
            //  path0 segment
            //  PersonData
            //  JobData
            //  AddressData
            //  CountryData
            //  VirtualResolvedObject
            Assert.AreEqual(8, schema.KnownTypes.Count(x => x.Kind == TypeKind.OBJECT));

            // expect a type for the root operation type
            Assert.IsTrue(schema.KnownTypes.Contains(Constants.ReservedNames.MUTATION_TYPE_NAME));
            Assert.IsTrue(schema.KnownTypes.Contains(Constants.ReservedNames.QUERY_TYPE_NAME));

            // expect a type representing the controller top level path
            Assert.IsTrue(schema.KnownTypes.Contains($"{Constants.ReservedNames.MUTATION_TYPE_NAME}_path0"));

            // expect a type for the method return type
            Assert.IsTrue(schema.KnownTypes.Contains(nameof(PersonData)));

            // person data contains job data
            Assert.IsTrue(schema.KnownTypes.Contains(typeof(JobData), TypeKind.OBJECT));

            // person data contains address data
            Assert.IsTrue(schema.KnownTypes.Contains(typeof(AddressData), TypeKind.OBJECT));

            // address data contains country data
            Assert.IsTrue(schema.KnownTypes.Contains(typeof(CountryData), TypeKind.OBJECT));
        }
        public void EnsureGraphType_ScalarTwice_EndsUpInScalarCollectionOnce()
        {
            var schema  = new GraphSchema() as ISchema;
            var manager = new GraphSchemaManager(schema);

            manager.EnsureGraphType(typeof(int));
            manager.EnsureGraphType(typeof(int));

            Assert.AreEqual(2, schema.KnownTypes.Count);  // added type + query
            Assert.IsTrue(schema.KnownTypes.Contains(GraphQLProviders.ScalarProvider.RetrieveScalar(typeof(int))));
            Assert.IsTrue(schema.KnownTypes.Contains(GraphQLProviders.ScalarProvider.RetrieveScalar(Constants.ScalarNames.INT)));
            Assert.IsTrue(schema.KnownTypes.Contains(typeof(int)));
        }
        public void EnsureGraphType_NormalObject_IsAddedWithTypeReference()
        {
            var schema  = new GraphSchema() as ISchema;
            var manager = new GraphSchemaManager(schema);

            manager.EnsureGraphType(typeof(CountryData));

            // CountryData, string, float?, Query
            Assert.AreEqual(4, schema.KnownTypes.Count);
            Assert.AreEqual(3, schema.KnownTypes.TypeReferences.Count());

            Assert.IsTrue(schema.KnownTypes.Contains(typeof(CountryData), TypeKind.OBJECT));
            Assert.IsTrue(schema.KnownTypes.Contains("CountryData"));
        }
        public void EnsureGraphType_ListT_AfterManualAddOfScalar_Succeeds()
        {
            var schema  = new GraphSchema() as ISchema;
            var manager = new GraphSchemaManager(schema);

            var intScalar = GraphQLProviders.ScalarProvider.RetrieveScalar(typeof(int));

            schema.KnownTypes.EnsureGraphType(intScalar, typeof(int));
            manager.EnsureGraphType(typeof(List <int>));

            Assert.AreEqual(2, schema.KnownTypes.Count);  // added type + query
            Assert.IsTrue(schema.KnownTypes.Contains(typeof(int)));
            Assert.IsTrue(schema.KnownTypes.Contains(Constants.ScalarNames.INT));
        }
        public void EnsureGraphType_WhenTwoControllersDecalreTheNameRootRouteName_AMeaningfulExceptionisThrown()
        {
            var schema = new GraphSchema() as ISchema;

            schema.SetNoAlterationConfiguration();
            var manager = new GraphSchemaManager(schema);

            manager.EnsureGraphType <ControllerWithRootName1>();

            Assert.Throws <GraphTypeDeclarationException>(() =>
            {
                manager.EnsureGraphType <ControllerWithRootName2>();
            });
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Validate the architecture
        /// </summary>
        /// <param name="graph">The graph</param>
        public void ValidateArchitecture(Graph graph)
        {
            if (graph == null)
            {
                throw new ArgumentNullException("graph");
            }

            // Uncomment the line below to debug this extension during validation
            // System.Windows.Forms.MessageBox.Show("Attach to GraphCmd.exe with process id " + System.Diagnostics.Process.GetCurrentProcess().Id);

            // Get the graph schema
            GraphSchema schema = graph.DocumentSchema;

            // Get the category for our custom property
            GraphProperty customPropertyCategory = schema.FindProperty(Validator1Property.FullName);

            if (customPropertyCategory == null)
            {
                // The property has not been used in the layer diagram. No need to validate further
                return;
            }

            // Get all layers on the diagram
            foreach (GraphNode layer in graph.Nodes.GetByCategory("Dsl.Layer"))
            {
                // Get the required regex property from the layer node
                string regexPattern = layer[customPropertyCategory] as string;
                if (!string.IsNullOrEmpty(regexPattern))
                {
                    Regex regEx = new Regex(regexPattern);

                    // Get all referenced types in this layer including those from nested layers so each
                    // type is validated against all containing layer constraints.
                    foreach (GraphNode containedType in layer.FindDescendants().Where(node => node.HasCategory("CodeSchema_Type")))
                    {
                        // Check the type name against the required regex
                        CodeGraphNodeIdBuilder builder = new CodeGraphNodeIdBuilder(containedType.Id, graph);
                        string typeName = builder.Type.Name;
                        if (!regEx.IsMatch(typeName))
                        {
                            // Log an error
                            string message = string.Format(CultureInfo.CurrentCulture, Resources.InvalidTypeNameMessage, typeName);
                            this.LogValidationError(graph, typeName + "TypeNameError", message, GraphErrorLevel.Error, layer, new GraphNode[] { containedType });
                        }
                    }
                }
            }
        }
        public void AddSingleQueryAction_AllDefaults_EnsureTypeStructure()
        {
            var schema  = new GraphSchema() as ISchema;
            var manager = new GraphSchemaManager(schema);

            manager.EnsureGraphType <SimpleMethodController>();

            // scalars for arguments on the method exists
            Assert.IsTrue(schema.KnownTypes.Contains(GraphQLProviders.ScalarProvider.RetrieveScalar(Constants.ScalarNames.STRING)));
            Assert.IsTrue(schema.KnownTypes.Contains(GraphQLProviders.ScalarProvider.RetrieveScalar(Constants.ScalarNames.INT)));

            // return type exists as an object type
            var returnType = typeof(SimpleMethodController).GetMethod(nameof(SimpleMethodController.TestActionMethod)).ReturnType;

            Assert.IsTrue(schema.KnownTypes.Contains(returnType, TypeKind.OBJECT));
        }
Ejemplo n.º 25
0
        public void AddASubscriptionAction_WithoutUpdatingTheConfiguration_ThrowsDeclarationException()
        {
            using var restorePoint = new GraphQLProviderRestorePoint();

            GraphQLProviders.TemplateProvider = new SubscriptionEnabledTemplateProvider();
            var schema = new GraphSchema() as ISchema;

            schema.SetNoAlterationConfiguration();

            // do not tell the schema to allow the subscription operation type
            // schema.SetSubscriptionAllowances();

            // attempt to add a controller with a subscription
            Assert.Throws <ArgumentOutOfRangeException>(() =>
            {
                var manager = new GraphSchemaManager(schema);
                manager.EnsureGraphType <SimpleMethodController>();
            });
        }
Ejemplo n.º 26
0
        public QueryParser(Parameters parameters, GraphSchema graph, IClassCache cache)
        {
            IsParsed = false;

            ClassProperties = graph.Vertices
                              .Select(v => v.Value.Properties)
                              .SelectMany(x => x).Select(x => x.Name)
                              .Distinct();

            OrderBy = new OrderByClauseParser <TRootVertex>(x => _GetTokens(x), parameters.OrderBy, graph, TermHelper.OrderByTerms);
            Select  = new SelectClauseParser <TRootVertex>(x => _GetTokens(x), parameters.Select, graph, TermHelper.SelectTerms);
            Filter  = new FilterClauseParser <TRootVertex>(x => _GetTokens(x), parameters.Filter, TermHelper.FilterTerms);
            Expand  = new ExpandClauseParser <TRootVertex>(x => _GetTokens(x), parameters.Expand, graph, Select, Filter, TermHelper.ExpandTerms);

            _Graph = graph;
            Cache  = cache;

            Parse();
        }
        public void EnsureGraphType_WithSubTypes_AreAddedCorrectly()
        {
            var schema = new GraphSchema() as ISchema;

            schema.SetNoAlterationConfiguration();
            var manager = new GraphSchemaManager(schema);

            manager.EnsureGraphType(typeof(PersonData));

            Assert.AreEqual(10, schema.KnownTypes.Count); // added types + query
            Assert.IsTrue(schema.KnownTypes.Contains(typeof(AddressData)));
            Assert.IsTrue(schema.KnownTypes.Contains(typeof(PersonData)));
            Assert.IsTrue(schema.KnownTypes.Contains(typeof(CountryData)));
            Assert.IsTrue(schema.KnownTypes.Contains(typeof(JobData)));
            Assert.IsTrue(schema.KnownTypes.Contains(typeof(string)));
            Assert.IsTrue(schema.KnownTypes.Contains(typeof(float)));
            Assert.IsTrue(schema.KnownTypes.Contains(typeof(float?)));
            Assert.IsTrue(schema.KnownTypes.Contains(typeof(uint)));
            Assert.IsTrue(schema.KnownTypes.Contains(typeof(decimal)));
        }
        public void EnsureGraphType_WhenRootControllerActionOfSameNameAsAType_IsAdded_ThrowsException()
        {
            var schema = new GraphSchema() as ISchema;

            schema.SetNoAlterationConfiguration();
            var manager = new GraphSchemaManager(schema);

            // ThingController declares two routes
            // [Query]/Thing  (A root operation)
            // [Query]/Thing/moreData  (a nested operation under a "thing" controller)
            // there is also a type [Type]/Thing in the schema
            //
            // this should create an impossible situation where
            // [Query]/Thing returns the "Thing" graph type
            // and the controller will try to nest "moreData" into this OBJECT type
            // which should fail
            Assert.Throws <GraphTypeDeclarationException>(() =>
            {
                manager.EnsureGraphType <ThingController>();
            });
        }
        public void AddSingleQueryAction_NestedRouting_EnsureTypeStructure()
        {
            var schema = new GraphSchema();

            schema.SetNoAlterationConfiguration();

            var manager = new GraphSchemaManager(schema);

            manager.EnsureGraphType <NestedQueryMethodController>();

            // query root exists, mutation does not (nothing was added to it)
            Assert.AreEqual(1, schema.OperationTypes.Count);
            Assert.IsTrue(schema.OperationTypes.ContainsKey(GraphCollection.Query));
            Assert.IsFalse(schema.OperationTypes.ContainsKey(GraphCollection.Mutation));

            Assert.AreEqual(7, schema.KnownTypes.Count);

            // expect 2 scalars
            Assert.IsTrue(schema.KnownTypes.Contains(GraphQLProviders.ScalarProvider.RetrieveScalar(Constants.ScalarNames.FLOAT)));
            Assert.IsTrue(schema.KnownTypes.Contains(GraphQLProviders.ScalarProvider.RetrieveScalar(Constants.ScalarNames.DATETIME)));

            // expect 5 types to be generated
            // ----------------------------------
            // the query operation type
            // the top level field representing the controller, "path0"
            // the middle level defined on the method "path1"
            // the return type from the method itself
            // the return type of the routes
            Assert.IsTrue(schema.KnownTypes.Contains("Query"));
            Assert.IsTrue(schema.KnownTypes.Contains("Query_path0"));
            Assert.IsTrue(schema.KnownTypes.Contains("Query_path0_path1"));
            Assert.IsTrue(schema.KnownTypes.Contains(nameof(TwoPropertyObjectV2)));
            Assert.IsTrue(schema.KnownTypes.Contains(nameof(VirtualResolvedObject)));

            // expect 2 actual reference type to be assigned
            //      the return type from the method and the virtual result fro the route
            // all others are virtual types in this instance
            Assert.IsTrue(schema.KnownTypes.Contains(typeof(TwoPropertyObjectV2), TypeKind.OBJECT));
            Assert.IsTrue(schema.KnownTypes.Contains(typeof(VirtualResolvedObject), TypeKind.OBJECT));
        }
Ejemplo n.º 30
0
        public void ActionTemplate_CreateUnionType_PropertyCheck()
        {
            var schema = new GraphSchema();

            schema.SetNoAlterationConfiguration();

            var action = TemplateHelper.CreateActionMethodTemplate <UnionTestController>(nameof(UnionTestController.TwoTypeUnion));
            var union  = new UnionGraphTypeMaker(schema).CreateGraphType(action.UnionProxy, TypeKind.OBJECT);

            Assert.IsNotNull(union);
            Assert.IsTrue(union is UnionGraphType);
            Assert.AreEqual("FragmentData", union.Name);
            Assert.IsNull(union.Description);

            Assert.AreEqual(2, union.PossibleGraphTypeNames.Count());
            Assert.AreEqual(2, union.PossibleConcreteTypes.Count());

            Assert.IsTrue(union.PossibleGraphTypeNames.Contains(nameof(UnionDataA)));
            Assert.IsTrue(union.PossibleGraphTypeNames.Contains(nameof(UnionDataB)));
            Assert.IsTrue(union.PossibleConcreteTypes.Contains(typeof(UnionDataA)));
            Assert.IsTrue(union.PossibleConcreteTypes.Contains(typeof(UnionDataB)));
        }
Ejemplo n.º 31
0
        public void AddSingleSubscriptionAction_AllDefaults_EnsureFieldStructure()
        {
            using var restorePoint = new GraphQLProviderRestorePoint();

            GraphQLProviders.TemplateProvider = new SubscriptionEnabledTemplateProvider();
            var schema = new GraphSchema() as ISchema;

            schema.SetNoAlterationConfiguration();
            schema.SetSubscriptionAllowances();

            var manager = new GraphSchemaManager(schema);

            manager.EnsureGraphType <SimpleMethodController>();

            // query always exists
            // subscription root was found via the method parsed
            // mutation was not provided
            Assert.IsTrue(schema.OperationTypes.ContainsKey(GraphCollection.Query));
            Assert.IsFalse(schema.OperationTypes.ContainsKey(GraphCollection.Mutation));
            Assert.IsTrue(schema.OperationTypes.ContainsKey(GraphCollection.Subscription));

            // field for the controller exists
            var topFieldName = nameof(SimpleMethodController).Replace(Constants.CommonSuffix.CONTROLLER_SUFFIX, string.Empty);

            Assert.IsTrue(schema.OperationTypes[GraphCollection.Subscription].Fields.ContainsKey(topFieldName));

            // ensure the field on the subscription operation  is the right name (i.e. the controller name)
            var topField = schema.OperationTypes[GraphCollection.Subscription][topFieldName];

            Assert.IsNotNull(topField);

            var type = schema.KnownTypes.FindGraphType(topField) as IObjectGraphType;

            var action = TemplateHelper.CreateFieldTemplate <SimpleMethodController>(nameof(SimpleMethodController.TestActionMethod));

            // ensure the action was put into the field collection of the controller operation
            Assert.IsTrue(type.Fields.ContainsKey(action.Route.Name));
        }
Ejemplo n.º 32
0
        public async Task <ActionResult> Post([FromBody] GraphQLQuery query)
        {
            var schema = new GraphSchema(_authorDetails);

            var inputs = query.Variables.ToInputs();

            var result = await new DocumentExecuter().ExecuteAsync(_ =>
            {
                _.Schema        = _schema.GraphQLSchema;
                _.Query         = query.Query;
                _.OperationName = query.OperationName;
                _.Inputs        = inputs;
                _.EnableMetrics = false;
            });

            if (result.Errors?.Count > 0)
            {
                return(BadRequest());
            }

            //
            return(Ok(result.Data));
        }
Ejemplo n.º 33
0
        void Process()
        {
            GraphSchema assemblySchema = new GraphSchema("ildependsSchema");
            UnresolvedCategory = assemblySchema.Categories.AddNewCategory("Unresolved");
            AssemblyCategory = assemblySchema.Categories.AddNewCategory("CodeSchema_Assembly");

            string windir = Environment.GetEnvironmentVariable("WINDIR");
            _paths.Add(windir + @"\Microsoft.NET\Framework\v4.0.30319");

            _host = new ConsoleHostEnvironment(_paths.ToArray(), true);

            Graph graph = new Graph();
            graph.AddSchema(assemblySchema);

            GraphConditionalStyle errorStyle = new GraphConditionalStyle(graph);
            GraphCondition condition = new GraphCondition(errorStyle);
            condition.Expression = "HasCategory('Unresolved')";
            GraphSetter setter = new GraphSetter(errorStyle, "Icon");
            setter.Value = "pack://application:,,,/Microsoft.VisualStudio.Progression.GraphControl;component/Icons/kpi_red_sym2_large.png";
            graph.Styles.Add(errorStyle);

            foreach (var dir in _directories)
            {
                foreach (var target in Directory.GetFiles(dir, "*.dll", SearchOption.AllDirectories))
                {
                    _files.Add(Path.GetFileName(target), target);
                }
            }

            foreach (String fileName in this._files.Values)
            {
                String fullPath = Path.GetFullPath(fileName);
                try
                {
                    Console.WriteLine("Processing: " + fullPath);
                    IAssembly assembly = _host.LoadUnitFrom(fileName) as IAssembly;
                    GraphNode root = graph.Nodes.GetOrCreate(GetNodeID(assembly.AssemblyIdentity), assembly.AssemblyIdentity.Name.Value, AssemblyCategory);
                    WalkDependencies(graph, root, assembly, new HashSet<IAssembly>());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("#Error: " + ex.Message);
                }
            }

            graph.Save(output);
        }
Ejemplo n.º 34
0
        static RoslynGraphProperties()
        {
            Schema = new GraphSchema("Roslyn");

            SymbolKind = Schema.Properties.AddNewProperty(
                id: "SymbolKind",
                dataType: typeof(SymbolKind),
                callback: () => new GraphMetadata(options: GraphMetadataOptions.Sharable | GraphMetadataOptions.Removable));

            TypeKind = Schema.Properties.AddNewProperty(
                id: "TypeKind",
                dataType: typeof(TypeKind),
                callback: () => new GraphMetadata(options: GraphMetadataOptions.Sharable | GraphMetadataOptions.Removable));

            MethodKind = Schema.Properties.AddNewProperty(
                id: "MethodKind",
                dataType: typeof(MethodKind),
                callback: () => new GraphMetadata(options: GraphMetadataOptions.Sharable | GraphMetadataOptions.Removable));

            DeclaredAccessibility = Schema.Properties.AddNewProperty(
                id: "DeclaredAccessibility",
                dataType: typeof(Accessibility),
                callback: () => new GraphMetadata(options: GraphMetadataOptions.Sharable | GraphMetadataOptions.Removable));

            SymbolModifiers = Schema.Properties.AddNewProperty(
                id: "SymbolModifiers",
                dataType: typeof(DeclarationModifiers),
                callback: () => new GraphMetadata(options: GraphMetadataOptions.Sharable | GraphMetadataOptions.Removable));

            ExplicitInterfaceImplementations = Schema.Properties.AddNewProperty(
                id: "ExplicitInterfaceImplementations",
                dataType: typeof(IList<SymbolKey>),
                callback: () => new GraphMetadata(options: GraphMetadataOptions.Sharable | GraphMetadataOptions.Removable));

            SymbolId = Schema.Properties.AddNewProperty(
                id: "SymbolId",
                dataType: typeof(SymbolKey?),
                callback: () => new GraphMetadata(options: GraphMetadataOptions.Sharable | GraphMetadataOptions.Removable));

            ContextProjectId = Schema.Properties.AddNewProperty(
                id: "ContextProjectId",
                dataType: typeof(ProjectId),
                callback: () => new GraphMetadata(options: GraphMetadataOptions.Sharable | GraphMetadataOptions.Removable));

            ContextDocumentId = Schema.Properties.AddNewProperty(
                id: "ContextDocumentId",
                dataType: typeof(DocumentId),
                callback: () => new GraphMetadata(options: GraphMetadataOptions.Sharable | GraphMetadataOptions.Removable));

            Label = Schema.Properties.AddNewProperty(
                id: "Label",
                dataType: typeof(string),
                callback: () => new GraphMetadata(options: GraphMetadataOptions.Sharable | GraphMetadataOptions.Removable));

            FormattedLabelWithoutContainingSymbol = Schema.Properties.AddNewProperty(
                id: "FormattedLabelWithoutContainingSymbol",
                dataType: typeof(string),
                callback: () => new GraphMetadata(options: GraphMetadataOptions.Sharable | GraphMetadataOptions.Removable));

            FormattedLabelWithContainingSymbol = Schema.Properties.AddNewProperty(
                id: "FormattedLabelWithContainingSymbol",
                dataType: typeof(string),
                callback: () => new GraphMetadata(options: GraphMetadataOptions.Sharable | GraphMetadataOptions.Removable));

            Description = Schema.Properties.AddNewProperty(
                id: "Description",
                dataType: typeof(string),
                callback: () => new GraphMetadata(options: GraphMetadataOptions.Sharable | GraphMetadataOptions.Removable));

            DescriptionWithContainingSymbol = Schema.Properties.AddNewProperty(
                id: "DescriptionWithContainingSymbol",
                dataType: typeof(string),
                callback: () => new GraphMetadata(options: GraphMetadataOptions.Sharable | GraphMetadataOptions.Removable));
        }