Пример #1
0
 public GraphQLHttpServer(GraphQLServer server, JsonSerializerSettings serializerSettings = null)
 {
     Server = server;
     if (Server.Model == null)
     {
         Server.Initialize();
     }
     SerializerSettings = serializerSettings;
     if (SerializerSettings == null)
     {
         var stt = SerializerSettings = new JsonSerializerSettings();
         stt.Formatting       = Formatting.Indented;
         stt.ContractResolver = new DefaultContractResolver {
             NamingStrategy = new CamelCaseNamingStrategy()
         };
         SerializerSettings.MaxDepth = 50;
     }
     _varDeserializer = new JsonVariablesDeserializer();
     // hook to RequestPrepared to deserialize variables after query is parsed and var types are known
     Server.Events.RequestPrepared += Server_RequestPrepared;
 }
Пример #2
0
        public static void Init()
        {
            if (ThingsServer != null)
            {
                return;
            }
            if (File.Exists(LogFilePath))
            {
                File.Delete(LogFilePath);
            }
            try {
                var thingsBizApp = new ThingsApp();
                var thingsModule = new ThingsGraphQLModule();
                ThingsServer = new GraphQLServer(thingsBizApp);
                ThingsServer.RegisterModules(thingsModule);
                ThingsServer.Initialize();
                ThingsServer.Events.RequestCompleted += ThingsServer_RequestCompleted;
            } catch (ServerStartupException sEx) {
                LogText(sEx.ToText() + Environment.NewLine);
                LogText(sEx.GetErrorsAsText());
                throw;
            }
            // Printout
            var schemaGen = new SchemaDocGenerator();
            var schemaDoc = schemaGen.GenerateSchema(ThingsServer.Model);

            File.WriteAllText("_thingsApiSchema.txt", schemaDoc);

            _serializerSettings = new JsonSerializerSettings()
            {
                Formatting       = Formatting.Indented,
                ContractResolver = new DefaultContractResolver()
                {
                    NamingStrategy = new CamelCaseNamingStrategy()
                }
            };
        }