Esempio n. 1
0
 private void AppendDirs(GraphQLModelObject modelObj)
 {
     if (!modelObj.HasDirectives())
     {
         return;
     }
     foreach (ModelDirective dir in modelObj.Directives)
     {
         _builder.Append(" @");
         _builder.Append(dir.Def.Name);
         if (dir.Def.Args.Count > 0)
         {
             var nvList = new List <string>();
             for (int i = 0; i < dir.Def.Args.Count; i++)
             {
                 // if (dir.Attribute.ArgValues[i] == null) continue; //just skip it
                 var strArg = FormatArg(dir.Def.Args[i], dir.ModelAttribute.ArgValues[i]);
                 nvList.Add(strArg);
             }
             if (nvList.Count > 0)
             {
                 _builder.Append("(");
                 var strArgs = string.Join(", ", nvList);
                 _builder.Append(strArgs);
                 _builder.Append(")");
             }
         } //if
     }
 }         //method
Esempio n. 2
0
        public void Apply(GraphQLApiModel model, GraphQLModelObject element, object[] argValues)
        {
            var intro = element.Intro_;

            if (intro == null)
            {
                return;
            }
            intro.IsDeprecated      = true;
            intro.DeprecationReason = (string)argValues[0];
        }
Esempio n. 3
0
 private void ApplyDirectives(GraphQLModelObject modelObj)
 {
     if (!modelObj.HasDirectives())
     {
         return;
     }
     foreach (var dir in modelObj.Directives)
     {
         dir.Def.Handler.ModelDirectiveApply(_model, modelObj, dir.ArgValues);
     }
 }
Esempio n. 4
0
        } //method

        private void Visit(GraphQLModelObject modelObj, Action <GraphQLModelObject> action)
        {
            action(modelObj);
            switch (modelObj)
            {
            case ComplexTypeDef ctd: // object type and interface type
                foreach (var fld in ctd.Fields)
                {
                    Visit(fld, action);
                }
                break;

            case InputObjectTypeDef itd:
                foreach (var f in itd.Fields)
                {
                    Visit(f, action);
                }
                break;

            case EnumTypeDef etd:
                foreach (var enumFld in etd.Fields)
                {
                    Visit(enumFld, action);
                }
                break;

            case ScalarTypeDef _:
            case UnionTypeDef _:
            case InputValueDef _:
                // nothing to do
                break;

            case FieldDef fd:
                if (fd.Args != null)
                {
                    foreach (var a in fd.Args)
                    {
                        Visit(a, action);
                    }
                }
                break;

            case DirectiveDef dirDef:
                if (dirDef.Args != null)
                {
                    foreach (var a in dirDef.Args)
                    {
                        Visit(a, action);
                    }
                }
                break;
            } //switch
        }
Esempio n. 5
0
 private void ApplyDirectives(GraphQLModelObject obj)
 {
     if (obj.Directives == null || obj.Directives.Count == 0)
     {
         return;
     }
     foreach (var dir in obj.Directives)
     {
         var action = dir.Def.Handler as IModelDirectiveAction;
         if (action == null)
         {
             continue;
         }
         action.Apply(_model, obj, dir.ModelAttribute.ArgValues);
     }
 }
Esempio n. 6
0
 public void ModelDirectiveApply(GraphQLApiModel model, GraphQLModelObject element, object[] argValues)
 {
 }
        private IList <ModelDirective> BuildDirectivesFromAttributes(ICustomAttributeProvider clrObjectInfo,
                                                                     DirectiveLocation location, GraphQLModelObject owner)
        {
            var attrList = clrObjectInfo.GetCustomAttributes(inherit: true);

            if (attrList.Length == 0)
            {
                return(ModelDirective.EmptyList);
            }

            var dirList = new List <ModelDirective>();

            foreach (var attr in attrList)
            {
                if (!(attr is BaseDirectiveAttribute dirAttr))
                {
                    continue;
                }
                var dirAttrType = dirAttr.GetType();
                var dirDef      = _model.Directives.Values.FirstOrDefault(def => def.DirInfo.AttributeType == dirAttrType);
                if (dirDef == null)
                {
                    AddError($"{clrObjectInfo}: directive attribute {dirAttrType} not registered.");
                    continue;
                }
                var dir = new ModelDirective()
                {
                    Def = dirDef, ModelAttribute = dirAttr, Location = location
                };
                dirList.Add(dir);
            }
            return(dirList);
        } //method