I have the following configuration in my ApolloServer.
this is my file a.typeDef.ts
import { gql } from "apollo-server";
const typeDefs = gql`^
scalar JSON
type ConfigurationGetPayload {
configuration: JSON
}
extend type Query {
configurations(districtId: ID, schoolId: ID): ConfigurationGetPayload
}
`;
export default typeDefs;
this is my file a.resolvers.ts
import { Context } from "../../context";
import {
QueryConfigurationsArgs,
QueryIntegrationsArgs,
} from "../../resolvers/types.generated";
import GraphQLJSON from "graphql-type-json";
//import { GraphQLJSON } from "graphql-scalars";
const resolvers = {
JSON: GraphQLJSON,
Query: {
configurations: async (
root: null,
args: QueryConfigurationsArgs,
context: Context
): Promise<any> => {
//todo here my code
},
},
},
};
export default resolvers;
This is my file server.ts with the definition on ApolloServer
import { ApolloServer } from "apollo-server-express";
import { applyMiddleware } from "graphql-middleware";
import * as depthLimit from "graphql-depth-limit";
import { constructContext } from "./context";
import { permissions } from "./permissions";
import { ApolloServerPluginInlineTraceDisabled } from "apollo-server-core";
import { instancePlugin as serverLoggerResponsePlugin } from "./config/plugin/server.logger.response.plugin";
import { Application } from "./application";
import { IntegrationApi } from "./datasources/integration.api";
/* eslint-disable @typescript-eslint/no-var-requires */
const { BaseRedisCache } = require("apollo-server-cache-redis");
const Redis = require("ioredis");
const schema = Application.createSchemaForApollo();
const server = new ApolloServer({
validationRules: [depthLimit(7)],
cache:
process.env.NODE_ENV.toLowerCase() == "debug"
? null
: new BaseRedisCache({
client: new Redis({
host: process.env.REDIS_HOST,
}),
}),
plugins: [
ApolloServerPluginInlineTraceDisabled(),
serverLoggerResponsePlugin,
],
tracing: false,
debug: false,
introspection: process.env.NODE_ENV.toLowerCase() !== "production",
schema: applyMiddleware(schema, permissions),
context: async ({ req }) => await constructContext(req),
formatError: (err) => {
},
dataSources: () => ({
//my datasources
}),
});
export default server;
I need to do something like this
but I get the following error
> k12-api-service@1.0.0 build
> tsc
> k12-api-service@1.0.0 start
> node build/index.js
C:\Users\Itopia\source\repos\labs\api\node_modules\graphql\language\lexer.js:360
throw (0, _syntaxError.syntaxError)(source, pos, unexpectedCharacterMessage(code));
^
GraphQLError [Object]: Syntax Error: Cannot parse the unexpected character "^".
at syntaxError (C:\Users\Itopia\source\repos\labs\api\node_modules\graphql\error\syntaxError.js:15:10)
at readToken (C:\Users\Itopia\source\repos\labs\api\node_modules\graphql\language\lexer.js:360:40)
at Lexer.lookahead (C:\Users\Itopia\source\repos\labs\api\node_modules\graphql\language\lexer.js:75:108)
at Lexer.advance (C:\Users\Itopia\source\repos\labs\api\node_modules\graphql\language\lexer.js:58:35)
at Parser.expectToken (C:\Users\Itopia\source\repos\labs\api\node_modules\graphql\language\parser.js:1408:19)
at Parser.many (C:\Users\Itopia\source\repos\labs\api\node_modules\gi\node_modules\graphql\language\parser.js:115:25)
at Object.parse (C:\Users\Itopia\source\repos\labs\api\nodeapi\node__mdules\graphql\language\parser.js:115:25)
odules\graphql\language\parser.js:31:17) _modules\
at parseDocument (C:\Users\Itopia\source\repos\labs\api\node_ at parseDocument (C:\Users\Itopia\source\repos\labs\api\node_modulesmodules\graphql-tag\lib\graphql-tag.umd.js:69:34)
i\node_modules\graphql\language\parser.js:115:25)
at Object.parse (C:\Users\Itopia\source\repos\labs\api\node_modules\graphql\language\parser.js:31:17)
at parseDocument (C:\Users\Itopia\source\repos\labs\api\node_modules\graphql-tag\lib\graphql-tag.umd.js:69:34)
at gql (C:\Users\Itopia\source\repos\labs\api\node_modules\graphql-tag\lib\graphql-tag.umd.js:98:16) {
locations: [ { line: 1, column: 1 } ]
}
this is my package.json
{
"name": "k12-api-service",
"version": "1.0.0",
"description": "GraphQL API for the K12 Backend",
"main": "index.js",
"scripts": {
"build": "tsc",
"codegen": "graphql-codegen --config codegen.yml",
"test": "jasmine-ts --config=./spec/support/jasmine.json",
"coverage": "nyc --reporter=lcov --reporter=text npm run test",
"dev": "npm run build && npm run start",
"format": "npx prettier --write .",
"lint": "eslint src/**/*.ts --fix",
"prebuild": "npm run lint",
"predev": "npm run format && npm run lint",
"start": "node build/index.js"
},
"repository": {
"type": "git",
"url": "https://itopiadev@dev.azure.com/itopiadev/K12/_git/k12-api"
},
"author": "aleon@itopia.com",
"license": "UNLICENSED",
"private": true,
"dependencies": {
"@axelspringer/graphql-google-pubsub": "^2.1.0",
"@firebase/app-compat": "^0.1.23",
"@google-cloud/logging": "^9.8.3",
"@google-cloud/pubsub": "^1.7.3",
"@google-cloud/secret-manager": "^3.12.0",
"@graphql-tools/graphql-file-loader": "^6.2.7",
"@graphql-tools/load": "^6.2.8",
"@itopia/core": "^2.5.0",
"@itopia/logging": "^2.4.1",
"apollo-datasource-rest": "^0.10.0",
"apollo-server": "^2.25.3",
"apollo-server-cache-redis": "^3.3.1",
"apollo-server-express": "^2.25.3",
"apollo-server-plugin-base": "^0.10.4",
"async": "^2.6.4",
"async-parallel-foreach": "^1.0.1",
"compression": "^1.7.4",
"convert-array-to-csv": "^2.0.0",
"cors": "^2.8.5",
"cowsay": "^1.5.0",
"dotenv": "^8.6.0",
"express": "^4.18.1",
"firebase": "^8.10.1",
"firebase-admin": "^9.12.0",
"google-auth-library": "^7.14.1",
"got": "<12.0.0",
"graphql-depth-limit": "^1.1.0",
"graphql-middleware": "^6.1.21",
"graphql-modules": "^1.4.4",
"graphql-scalars": "^1.22.2",
"graphql-shield": "^7.5.0",
"graphql-type-json": "^0.3.2",
"gtoken": "^5.3.2",
"helmet": "^5.0.2",
"http": "0.0.1-security",
"i": "^0.3.7",
"ioredis": "^4.28.5",
"jwt-decode": "^3.1.2",
"lodash": "^4.17.21",
"moment": "^2.29.3",
"node-fetch": "^2.5.12",
"npm": "^7.24.2",
"permissions-policy": "^0.6.0",
"redis": "^4.5.1",
"s": "^1.0.0",
"underscore": "^1.13.3",
"uuid": "^8.3.2",
"winston": "^3.7.2"
},
"devDependencies": {
"@ert78gb/jasmine-ts": "^0.3.2",
"@graphql-codegen/cli": "^1.21.8",
"@graphql-codegen/typescript": "^1.23.0",
"@graphql-codegen/typescript-resolvers": "^1.20.0",
"@types/async": "^3.2.13",
"@types/compression": "^1.7.2",
"@types/express": "^4.17.13",
"@types/graphql-depth-limit": "^1.1.3",
"@types/ioredis": "^4.28.10",
"@types/jasmine": "^3.10.6",
"@types/node": "14.18.3",
"@types/node-fetch": "^2.6.1",
"@types/underscore": "^1.11.3",
"@types/uuid": "^8.3.4",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"eslint": "^7.32.0",
"eslint-plugin-import": "^2.26.0",
"graphql": "^15.8.0",
"jasmine": "^3.99.0",
"jasmine-reporters": "^2.4.0",
"jasmine-spec-reporter": "^7.0.0",
"npm-run-all": "^4.1.5",
"nyc": "^15.1.0",
"prettier": "^2.6.2",
"ts-node": "^10.3.0",
"typescript": "^4.6.4",
"typescript-eslint-parser": "^22.0.0"
},
"nodemonConfig": {
"watch": [
"src"
],
"ext": "ts",
"exec": "node_modules/.bin/ts-node ./src/app.ts"
},
"engines": {
"node": "14.x.x"
}
}
I have some interfaces like this and I want to return in a query some data type that I can transform to those interfaces. My goal is to produce my own JSON object
export interface IntegrationConfiguration {
id?: string;
integrationType?: string;
}
export interface MicrosoftIntegrationConfiguration
extends IntegrationConfiguration {
scopes?: string[];
}
export interface GoogleIntegrationConfiguration
extends IntegrationConfiguration {
clientId?: string;
scopes?: string[];
}
export interface LtiCanvasConfiguration extends IntegrationConfiguration {
accesstokenEndpoint?: string;
authConfigMethod?: string;
authConfigMethodKey?: string;
authenticationEndpoint?: string;
jsonUrl?: string;
method?: string;
name?: string;
url?: string;
redirectUris?: string[];
}