/// <summary>
        /// A simple function that takes a string and returns both the upper and lower case version of the string.
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task FunctionHandler(S3Event evnt, ILambdaContext context)
        {
            string bucket = evnt.Records[0].S3.Bucket.Name;
            string key    = evnt.Records[0].S3.Object.Key;

            Console.WriteLine(bucket);
            Console.WriteLine(key);

            string objectId = key.Substring(key.LastIndexOf("/") + 1);

            Console.WriteLine(objectId);

            var options = await new GraphQLHttpClientOptions()
                          .ConfigureAppSync(
                GraphQLEndpoint,
                appSyncClient.Config
                );

            _graphQlClient = new GraphQLHttpClient(options, new SystemTextJsonSerializer());

            var sfnInput = new SfnExecutionInput()
            {
                objectId  = objectId,
                Bucket    = bucket,
                SourceKey = key
            };

            var startWorkflowMutation = new GraphQLRequest
            {
                Query         = @"
                mutation StartSfnExecution(
                    $input: StartSfnExecutionInput!
                ) {
                    startSfnExecution(input: $input) {
                        executionArn
                        startDate
                    }
                }",
                OperationName = "StartSfnExecution",
                Variables     = new
                {
                    input = new
                    {
                        input           = JsonSerializer.Serialize(sfnInput),
                        stateMachineArn = StateMachineArn
                    },
                }
            };

            var workflowMutationResponse = await _graphQlClient.SendMutationAsync <StartWorkflowResult>(startWorkflowMutation);

            Console.WriteLine(JsonSerializer.Serialize(workflowMutationResponse.Data.startSfnExecution));

            var updatePhotoRequest = new GraphQLRequest
            {
                Query         = @"
                mutation UpdatePhotoMutation(
                    $input: UpdatePhotoInput!
                    $condition: ModelPhotoConditionInput
                ) {
                    updatePhoto(input: $input, condition: $condition) {
                        id
                        albumId
                        owner
                        uploadTime
                        bucket
                        sfnExecutionArn
                        processingStatus
                    }
                }",
                OperationName = "UpdatePhotoMutation",
                Variables     = new
                {
                    input = new
                    {
                        id = objectId,
                        sfnExecutionArn  = workflowMutationResponse.Data.startSfnExecution.executionArn,
                        processingStatus = "RUNNING"
                    }
                }
            };

            var photoUpdateMutationResponse = await _graphQlClient.SendMutationAsync <UpdatePhotoResponse>(updatePhotoRequest);

            Console.WriteLine(JsonSerializer.Serialize(photoUpdateMutationResponse.Data));
        }
Beispiel #2
0
        public static async Task Main(string[] args)
        {
            var apiKey        = "INSERT_BASE_64_USERID_AND_APIKEY";
            var apiHost       = "https://api.curri.com/graphql";
            var graphQLClient = new GraphQL.Client.Http.GraphQLHttpClient(apiHost, new NewtonsoftJsonSerializer());

            graphQLClient.HttpClient.DefaultRequestHeaders.Add("authorization", $"Basic ${apiKey}");

            var currentUserRequest = new GraphQLHttpRequest
            {
                Query = @"
                {
			        currentUser {
                        id
                        firstName
                        lastName
                    }
                }"
            };

            var currentUserResponse = await graphQLClient.SendQueryAsync <object>(currentUserRequest);

            Console.WriteLine();
            Console.WriteLine($"Current User: {currentUserResponse.Data.ToString()}");


            var quoteRequest = new GraphQLHttpRequest
            {
                Query = @"
                query DeliveryQuote ($origin: AddressInput, $destination: AddressInput, $deliveryMethod: String){
                    deliveryQuote (
                        destination: $destination
                        origin: $origin,
                        deliveryMethod: $deliveryMethod
                    ) {
                        id
                        fee
                        distance
                        duration
                        pickupDuration
                        deliveryMethod
                    }
                }",

                OperationName = "DeliveryQuote",
                Variables     = new
                {
                    deliveryMethod = "truck",
                    destination    = new {
                        name         = "Curri Incubator",
                        addressLine1 = "218 College Ave",
                        city         = "Mountain View",
                        state        = "CA",
                        postalCode   = 93001
                    },
                    origin = new
                    {
                        name         = "305 South Kalorama Street",
                        addressLine1 = "305 S Kalorama St",
                        city         = "Ventura",
                        state        = "CA",
                        postalCode   = 93001
                    }
                }
            };


            var quoteResponse = await graphQLClient.SendQueryAsync <DeliveryQuoteResponse>(quoteRequest);

            Console.WriteLine();
            Console.WriteLine($"Truck Quote: {quoteResponse.Data.ToString()}");


            var quoteId = quoteResponse.Data.DeliveryQuote.Id;

            Console.WriteLine($"Quote ID: {quoteResponse.Data.DeliveryQuote.Id}");

            var bookRequest = new GraphQLHttpRequest
            {
                Query = @"
                mutation BookDelivery ($data: BookDeliveryInput!){
                    bookDelivery (
                        data: $data
                    ) {
                        id
                        price
                        createdAt
                        deliveryMethod
                        deliveredAt
                    }
                }",

                OperationName = "BookDelivery",
                Variables     = new
                {
                    data = new
                    {
                        deliveryQuoteId = quoteResponse.Data.DeliveryQuote.Id
                    }
                }
            };

            var bookResponse = await graphQLClient.SendQueryAsync <object>(bookRequest);

            Console.WriteLine();
            Console.WriteLine($"Book Delivery: {bookResponse.Data.ToString()}");
        }
Beispiel #3
0
 async Task OnWSConnected(GraphQL.Client.Http.GraphQLHttpClient client)
 {
 }
Beispiel #4
0
        /// <summary>
        /// A simple function that takes a string and returns both the upper and lower case version of the string.
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task FunctionHandler(InputEvent input, ILambdaContext context)
        {
            string graphQlEndpoint = System.Environment.GetEnvironmentVariable(GRAPHQL_ENDPOINT);

            var options = await new GraphQLHttpClientOptions()
                          .ConfigureAppSync(
                graphQlEndpoint,
                appSyncClient.Config
                );

            _graphQlClient = new GraphQLHttpClient(options, new SystemTextJsonSerializer());


            const string UPDATE_PHOTO = @"
                mutation UpdatePhotoMutation(
                    $input: UpdatePhotoInput!
                    $condition: ModelPhotoConditionInput
                ) {
                    updatePhoto(input: $input, condition: $condition) {
                        id
                        fullsize {
                            key
                            width
                            height
                        }
                        thumbnail {
                            key
                            width
                            height
                        }
                        format
                        exifMake
                        exitModel
                        objectDetected
                        processingStatus
                        geoLocation {
                            latitude {
                                d
                                m
                                s
                                direction
                            }
                            longtitude {
                                d
                                m
                                s
                                direction
                            }
                        }
                    }
                }";

            var thumbnail = JsonSerializer.Deserialize <Thumbnail>(JsonSerializer.Serialize(input.ParallelResults[1]));

            List <Label> labels = JsonSerializer.Deserialize <List <Label> >(JsonSerializer.Serialize(input.ParallelResults[0]));

            var updatePhotoMutation = new GraphQLRequest
            {
                Query         = UPDATE_PHOTO,
                OperationName = "UpdatePhotoMutation",
                Variables     = new
                {
                    input = new
                    {
                        id = input.ObjectId,
                        processingStatus = "SUCCEEDED",
                        fullsize         = new {
                            key    = input.SourceKey,
                            width  = input.ExtractedMetadata?.Dimensions?.Width,
                            height = input.ExtractedMetadata?.Dimensions?.Height,
                        },
                        format    = input.ExtractedMetadata?.Format,
                        exifMake  = input.ExtractedMetadata?.ExifMake,
                        exitModel = input.ExtractedMetadata?.ExifModel,
                        thumbnail = new {
                            key    = thumbnail?.s3key,
                            width  = thumbnail?.width,
                            height = thumbnail?.height,
                        },
                        objectDetected = labels.Select(l => l.Name).ToArray(),
                        geoLocation    = input.ExtractedMetadata?.Geo
                    }
                }
            };


            var photoUpdateMutationResponse = await _graphQlClient.SendMutationAsync <object>(updatePhotoMutation);

            Console.WriteLine(JsonSerializer.Serialize(photoUpdateMutationResponse));
        }