Example #1
0
        public static void Initialize()
        {
            if (StarWarsHttpServer != null) //already initialized
            {
                return;
            }
            if (File.Exists(LogFilePath))
            {
                File.Delete(LogFilePath);
            }

            // create server and Http graphQL server
            var app            = new StarWarsApp();
            var starWarsServer = new GraphQLServer(app);

            starWarsServer.RegisterModules(new StarWarsApiModule());
            StarWarsHttpServer = new GraphQLHttpServer(starWarsServer);
            StartWebHost();

            // Write schema doc to file
            var schemaDoc = starWarsServer.Model.SchemaDoc;

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


            Client = new GraphQLClient(GraphQLEndPointUrl);
            Client.RequestCompleted += Client_RequestCompleted;
        }
Example #2
0
        private GraphQLHttpServer CreateGraphQLHttpServer()
        {
            var app    = new StarWarsApp();
            var server = new GraphQLServer(app);

            server.RegisterModules(new StarWarsApiModule());
            return(new GraphQLHttpServer(server));
        }
Example #3
0
        private GraphQLHttpServer CreateGraphQLHttpServer()
        {
            // create server and Http graphQL server
            var thingsBizApp = new ThingsApp();
            var thingsServer = new GraphQLServer(thingsBizApp);
            var thingsModule = new ThingsGraphQLModule();

            thingsServer.RegisterModules(thingsModule);
            var server = new GraphQLHttpServer(thingsServer);

            return(server);
        }
Example #4
0
 public RequestContext(GraphQLServer server, GraphQLRequest rawRequest, CancellationToken cancellationToken = default,
                       ClaimsPrincipal user = null, RequestQuota quota = null, object httpContext = null)
 {
     Server     = server;
     RawRequest = rawRequest;
     _externalCancellationToken = cancellationToken;
     User           = user;
     HttpContext    = httpContext;
     StartTimestamp = AppTime.GetTimestamp();
     Quota          = quota ?? Server.DefaultRequestQuota ?? new RequestQuota();
     // cancellation tokens, initial implementation of limiting request time by quota
     _cancellationTokenSource = new CancellationTokenSource(Quota.MaxRequestTime);
     _cancellationTokenSource.Token.Register(OnCancelled);
     if (_externalCancellationToken != default)
     {
         _externalCancellationToken.Register(OnExternalTokenCancelled);
     }
 }
Example #5
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;
 }
Example #6
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()
                }
            };
        }
Example #7
0
 public virtual void Init(GraphQLServer server)
 {
 }
Example #8
0
 public GraphQLApiModel(GraphQLServer server)
 {
     Server = server;
 }
Example #9
0
 public RequestHandler(GraphQLServer server, RequestContext requestContext)
 {
     _server         = server;
     _requestContext = requestContext;
 }
Example #10
0
 public ModelBuilder(GraphQLServer server)
 {
     _server    = server;
     _docLoader = new XmlDocumentationLoader();
 }