Files
smart-city-digital-twin-mar…/smart-app-city/frontend/node_modules/graphql/validation/rules/VariablesInAllowedPositionRule.js.flow
Eric FELIXINE e30ae8ed09 feat(smart-app): implement complete mobile app MVP
- App.tsx: full navigation (Auth stack + Main tabs with 5 screens)
- Auth: LoginScreen, RegisterScreen, ForgotPasswordScreen
- HomeScreen: dashboard with IoT metrics, weather widget, alerts, quick actions, sensors
- MapScreen: interactive map with layer toggles (6 layers)
- MarketplaceScreen: categories (6), products (5), search
- ChatScreen: AI chat with quick prompts (4), bot responses
- ProfileScreen: user info, stats, menu (9 items), logout
- AlertsScreen: alert list with severity, acknowledge
- SensorsScreen: sensor list with type filters (6 types), search
- ZonesScreen: zone cards with stats
- SettingsScreen: language picker (FR/EN/ES/DE), privacy, about
- Stores: iotStore (sensors, zones, alerts), notificationStore, uiStore + i18n
- Hooks: useSensors, useAlerts, useNotifications, useLocation
- Components: Card, Button, LoadingSpinner, ErrorBoundary, Header
- Services: iotService, notificationService (with axios API client)
- Utils: formatters (temp, AQI, noise, dates), validators (email, password, IBAN)
- Theme: colors.ts with full design system (Blue Ocean palette)
- Ditto: fixed MongoDB connection, new JWT secrets, official gateway image
2026-06-01 18:00:35 -04:00

99 lines
3.3 KiB
Plaintext

// @flow strict
import inspect from '../../jsutils/inspect';
import { GraphQLError } from '../../error/GraphQLError';
import { Kind } from '../../language/kinds';
import type { ValueNode } from '../../language/ast';
import type { ASTVisitor } from '../../language/visitor';
import type { GraphQLSchema } from '../../type/schema';
import type { GraphQLType } from '../../type/definition';
import { isNonNullType } from '../../type/definition';
import { typeFromAST } from '../../utilities/typeFromAST';
import { isTypeSubTypeOf } from '../../utilities/typeComparators';
import type { ValidationContext } from '../ValidationContext';
/**
* Variables passed to field arguments conform to type
*/
export function VariablesInAllowedPositionRule(
context: ValidationContext,
): ASTVisitor {
let varDefMap = Object.create(null);
return {
OperationDefinition: {
enter() {
varDefMap = Object.create(null);
},
leave(operation) {
const usages = context.getRecursiveVariableUsages(operation);
for (const { node, type, defaultValue } of usages) {
const varName = node.name.value;
const varDef = varDefMap[varName];
if (varDef && type) {
// A var type is allowed if it is the same or more strict (e.g. is
// a subtype of) than the expected type. It can be more strict if
// the variable type is non-null when the expected type is nullable.
// If both are list types, the variable item type can be more strict
// than the expected item type (contravariant).
const schema = context.getSchema();
const varType = typeFromAST(schema, varDef.type);
if (
varType &&
!allowedVariableUsage(
schema,
varType,
varDef.defaultValue,
type,
defaultValue,
)
) {
const varTypeStr = inspect(varType);
const typeStr = inspect(type);
context.reportError(
new GraphQLError(
`Variable "$${varName}" of type "${varTypeStr}" used in position expecting type "${typeStr}".`,
[varDef, node],
),
);
}
}
}
},
},
VariableDefinition(node) {
varDefMap[node.variable.name.value] = node;
},
};
}
/**
* Returns true if the variable is allowed in the location it was found,
* which includes considering if default values exist for either the variable
* or the location at which it is located.
*/
function allowedVariableUsage(
schema: GraphQLSchema,
varType: GraphQLType,
varDefaultValue: ?ValueNode,
locationType: GraphQLType,
locationDefaultValue: ?mixed,
): boolean {
if (isNonNullType(locationType) && !isNonNullType(varType)) {
const hasNonNullVariableDefaultValue =
varDefaultValue != null && varDefaultValue.kind !== Kind.NULL;
const hasLocationDefaultValue = locationDefaultValue !== undefined;
if (!hasNonNullVariableDefaultValue && !hasLocationDefaultValue) {
return false;
}
const nullableLocationType = locationType.ofType;
return isTypeSubTypeOf(schema, varType, nullableLocationType);
}
return isTypeSubTypeOf(schema, varType, locationType);
}