JS: Add test case for GraphQLObjectType

This commit is contained in:
Napalys Klicius
2025-09-19 14:23:40 +02:00
parent 2cd1d2fd2f
commit d88bc8e408

View File

@@ -1,5 +1,5 @@
const express = require('express');
const { graphql, buildSchema } = require('graphql');
const { graphql, buildSchema, GraphQLObjectType, GraphQLString } = require('graphql');
const app = express();
app.use(express.json());
@@ -53,4 +53,30 @@ app.post('/graphql', async (req, res) => {
rootValue: root1,
variableValues: variables
});
const MutationType = new GraphQLObjectType({
name: 'Mutation',
fields: {
runEval: {
type: GraphQLString,
args: {
value: { type: GraphQLString }
},
resolve: (_, { value }, context) => { // $ MISSING: Source[js/code-injection]
return eval(value); // $ MISSING: Alert[js/code-injection]
}
}
}
});
const schema = new GraphQLSchema({
query: QueryType,
mutation: MutationType
});
await graphql({
schema,
source: query,
variableValues: variables
});
});