# EDGE API Server ### Structure api - apierror: api error package with different utilities for creating and using different api errors - bsl: everything bsl related for api server - types: go types for calling bsl apis - clients: clients specific to api - graph: all code related to running the gql gen graphql api - generated: generated code from the gqlgen plugin - mapper: mapper functions to map to and from gqlgen models - model: model for graphql types generated by gqlgen - resolver: generated code to wire up logic for each graphql query and mutation - schema: the graphql schema used to generate the gql gen server - setup: code for setting up and running the gql server - test: test utilities for graph package - utils: helper utilities for working with graphql - middleware: middleware added to the graphql server for things like auth and validation - mocks: service and client mocks for unit testing - services: logic for resolvers - sql: code to interact with sql - **testutils**: some helpers for unit testing (need to work to refactor) - totp: code related to totp functionality - **types**: Need to refactor types to be with clients or with whatever is using them - **utils**: refactor into better place (separate libraries, mapper, etc) ### How to run Edge API - Go into `cmd/edge/api`, create an `.env` file: ``` touch .env ``` - Here is the template of how that file will look: ``` APP_ENV="local-dev" PORT=5000 APP_SECRET="SUPER_SECRET_SECRET" BSP_ENDPOINT="https://api.ncr.com" BSP_ROOT="/customers/" BSP_SITE_ENDPOINT="https://api.ncr.com" BSP_ORGANIZATION_PREFIX="edge-dev1" TOP_LEVEL_PROJECT_ID="ret-edge-dev1-foreman" INTEGRATION_TEST=false GOOGLE_APPLICATION_CREDENTIALS="SERVICE_ACCOUNT_KEY" SQL_CONNECTION_NAME="ret-edge-dev1-foreman:us-central1:edge-dev1" SQL_USER="bff-sa@ret-edge-dev1-foreman.iam" SQL_DB_NAME="edge-dev1" BSL_ORG="edge-dev1-retail-b526aa" BSP_RESET_URL="https://dev1.edge-preprod.dev/reset-password" OKTA_ISSUER="https://login.ncr.com/oauth2/default" OKTA_CLIENT_ID="0oa4znv55ixacgyLx697" PS_BQ_TABLE="ret-edge-dev1-foreman.ctlfishpubsub.resources" ``` - ***To acquire all the credentioals you need for this file, please reach out to the API team, and we will send you the proper values for your `.env` file and service accounts *** - After acquiring the input, paste them inside ur `.env` file and save. - To run `Edge API`, run the following command ``` go run cmd/edge/api/server.go ``` - If the `Edge API` ran successfully, you will get this message: ``` {"level":"warn","error":"unable to load in-cluster configuration, KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT must be defined","time":"2023-11-01T14:41:18-04:00","message":"failed to load in-cluster config, attempting to use local kubeconfig"} {"severity":"INFO","time":"2023-11-01T14:41:21-04:00","message":"connect to http://localhost:8080/graphiql/ for GraphiQL","version":"dev","logging.googleapis.com/sourceLocation":{"function":"edge-infra.dev/pkg/edge/api/graph/setup.Server","file":"/Users/QLID/edge-infra/pkg/edge/api/graph/setup/bff_setup.go","line":247}} ``` - Then go to your browser, type `http://localhost:8080/graphiql/`