How to use the getNamedType function from graphql
Find comprehensive JavaScript graphql.getNamedType code examples handpicked from public code repositorys.
graphql.getNamedType is a function that returns the named type of a GraphQL type, which can be useful for working with GraphQL schemas and types.
GitHub: mercurius-js/validation
48 49 50 51 52 53 54 55 56 57
} function getTypeInfo (graphQLType) { const isNonNull = isNonNullType(graphQLType.type) const type = isNonNull ? graphQLType.type.ofType : graphQLType.type return [type, getNamedType(type), isNonNull] } module.exports = { validateOpts,
GitHub: sameer-coder/validation
47 48 49 50 51 52 53 54 55 56
return {} } function getTypeInfo (graphQLType) { const type = isNonNullType(graphQLType.type) ? graphQLType.type.ofType : graphQLType.type return [type, getNamedType(type)] } module.exports = { validateOpts,
+ 3 other calls in file
How does graphql.getNamedType work?
graphql.getNamedType
works by taking a single input, which is a GraphQL type.
The function returns the named type of the input type, which may be different than the input type if the input type is a list or non-null type.
For example, if the input type is a GraphQLNonNull
wrapping a GraphQLString
, getNamedType
would return GraphQLString
.
If the input type is a GraphQLList
wrapping a GraphQLNonNull
wrapping a GraphQLString
, getNamedType
would return GraphQLString
.
By using graphql.getNamedType
, you can access the underlying named type of a GraphQL type, which can be useful for working with GraphQL schemas and types.
129 130 131 132 133 134 135 136 137 138
for (const type of Object.values(types)) { if (isObjectType(type) && !isDefaultType(type.name)) { const serviceForType = typeToServiceMap[type.name] for (const field of Object.values(type.getFields())) { const fieldType = getNamedType(field.type) if ( fieldType.astNode && fieldType.astNode.kind === Kind.ENUM_TYPE_DEFINITION ) {
3778 3779 3780 3781 3782 3783 3784 3785 3786 3787
} = _ref, config = _objectWithoutProperties(_ref, _excluded$2); return meta => { var _config$ui, _config$ui2, _config$ui2$itemView, _config$ui3, _config$ui3$listView; const usableField = typeof field === 'function' ? field(meta.lists) : field; const namedType = graphql.getNamedType(usableField.type.graphQLType); const hasRequiredArgs = usableField.args && Object.values(usableField.args).some(x => x.type.kind === 'non-null' && x.defaultValue === undefined); if ((!graphql.isLeafType(namedType) || hasRequiredArgs) && !((_config$ui = config.ui) !== null && _config$ui !== void 0 && _config$ui.query) && (((_config$ui2 = config.ui) === null || _config$ui2 === void 0 ? void 0 : (_config$ui2$itemView = _config$ui2.itemView) === null || _config$ui2$itemView === void 0 ? void 0 : _config$ui2$itemView.fieldMode) !== 'hidden' || ((_config$ui3 = config.ui) === null || _config$ui3 === void 0 ? void 0 : (_config$ui3$listView = _config$ui3.listView) === null || _config$ui3$listView === void 0 ? void 0 : _config$ui3$listView.fieldMode) !== 'hidden')) { throw new Error(`The virtual field at ${meta.listKey}.${meta.fieldKey} requires a selection for the Admin UI but ui.query is unspecified and ui.listView.fieldMode and ui.itemView.fieldMode are not both set to 'hidden'.\n` + `Either set ui.query with what the Admin UI should fetch or hide the field from the Admin UI by setting ui.listView.fieldMode and ui.itemView.fieldMode to 'hidden'.\n` + `When setting ui.query, it is interpolated into a GraphQL query like this:\n` + `query {\n` + ` ${core.getGqlNames({ listKey: meta.listKey,
+ 2 other calls in file
Ai Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
const { GraphQLString, GraphQLNonNull, GraphQLList, getNamedType, } = require("graphql"); // Define a GraphQL type const nonNullStringType = new GraphQLNonNull(GraphQLString); // Log the named type of the GraphQL type console.log(getNamedType(nonNullStringType).name); // GraphQLString // Define another GraphQL type const listType = new GraphQLList(new GraphQLNonNull(GraphQLString)); // Log the named type of the GraphQL type console.log(getNamedType(listType).name); // GraphQLString
In this example, we use graphql.getNamedType to get the named type of a GraphQL type. We first define a GraphQL type nonNullStringType that is a non-null GraphQLString. We then pass nonNullStringType to getNamedType to get the named type of the GraphQL type, which is GraphQLString. We then define another GraphQL type listType that is a list of non-null GraphQLString. We again pass listType to getNamedType to get the named type of the GraphQL type, which is again GraphQLString. The resulting output demonstrates how graphql.getNamedType can be used to get the named type of a GraphQL type, which can be useful for working with GraphQL schemas and types.
graphql.GraphQLNonNull is the most popular function in graphql (4226 examples)