graphql-relay
Advanced tools
Comparing version 0.9.0 to 0.10.0
@@ -6,3 +6,2 @@ import type { | ||
} from './connection'; | ||
interface ArraySliceMetaInfo { | ||
@@ -12,3 +11,2 @@ sliceStart: number; | ||
} | ||
/** | ||
@@ -19,7 +17,6 @@ * A simple function that accepts an array and connection arguments, and returns | ||
*/ | ||
export function connectionFromArray<T>( | ||
export declare function connectionFromArray<T>( | ||
data: ReadonlyArray<T>, | ||
args: ConnectionArguments, | ||
): Connection<T>; | ||
/** | ||
@@ -29,7 +26,6 @@ * A version of `connectionFromArray` that takes a promised array, and returns a | ||
*/ | ||
export function connectionFromPromisedArray<T>( | ||
export declare function connectionFromPromisedArray<T>( | ||
dataPromise: Promise<ReadonlyArray<T>>, | ||
args: ConnectionArguments, | ||
): Promise<Connection<T>>; | ||
/** | ||
@@ -44,3 +40,3 @@ * Given a slice (subset) of an array, returns a connection object for use in | ||
*/ | ||
export function connectionFromArraySlice<T>( | ||
export declare function connectionFromArraySlice<T>( | ||
arraySlice: ReadonlyArray<T>, | ||
@@ -50,3 +46,2 @@ args: ConnectionArguments, | ||
): Connection<T>; | ||
/** | ||
@@ -56,3 +51,3 @@ * A version of `connectionFromArraySlice` that takes a promised array slice, | ||
*/ | ||
export function connectionFromPromisedArraySlice<T>( | ||
export declare function connectionFromPromisedArraySlice<T>( | ||
dataPromise: Promise<ReadonlyArray<T>>, | ||
@@ -62,21 +57,17 @@ args: ConnectionArguments, | ||
): Promise<Connection<T>>; | ||
/** | ||
* Creates the cursor string from an offset. | ||
*/ | ||
export function offsetToCursor(offset: number): ConnectionCursor; | ||
export declare function offsetToCursor(offset: number): ConnectionCursor; | ||
/** | ||
* Extracts the offset from the cursor string. | ||
*/ | ||
export function cursorToOffset(cursor: ConnectionCursor): number; | ||
export declare function cursorToOffset(cursor: ConnectionCursor): number; | ||
/** | ||
* Return the cursor associated with an object in an array. | ||
*/ | ||
export function cursorForObjectInConnection<T>( | ||
export declare function cursorForObjectInConnection<T>( | ||
data: ReadonlyArray<T>, | ||
object: T, | ||
): ConnectionCursor | null; | ||
/** | ||
@@ -87,5 +78,6 @@ * Given an optional cursor and a default offset, returns the offset | ||
*/ | ||
export function getOffsetWithDefault( | ||
export declare function getOffsetWithDefault( | ||
cursor: ConnectionCursor | null | undefined, | ||
defaultOffset: number, | ||
): number; | ||
export {}; |
@@ -0,17 +1,9 @@ | ||
import { GraphQLNonNull, GraphQLObjectType } from 'graphql'; | ||
import type { | ||
GraphQLNonNull, | ||
GraphQLNamedType, | ||
GraphQLScalarType, | ||
GraphQLObjectType, | ||
GraphQLNamedOutputType, | ||
GraphQLFieldConfigArgumentMap, | ||
GraphQLFieldConfigMap, | ||
GraphQLFieldConfig, | ||
GraphQLFieldResolver, | ||
Thunk, | ||
ThunkObjMap, | ||
} from 'graphql'; | ||
interface ForwardConnectionArgs { | ||
after: { type: GraphQLScalarType }; | ||
first: { type: GraphQLScalarType }; | ||
} | ||
/** | ||
@@ -21,10 +13,3 @@ * Returns a GraphQLFieldConfigArgumentMap appropriate to include on a field | ||
*/ | ||
export const forwardConnectionArgs: GraphQLFieldConfigArgumentMap & | ||
ForwardConnectionArgs; | ||
interface BackwardConnectionArgs { | ||
before: { type: GraphQLScalarType }; | ||
last: { type: GraphQLScalarType }; | ||
} | ||
export declare const forwardConnectionArgs: GraphQLFieldConfigArgumentMap; | ||
/** | ||
@@ -34,5 +19,3 @@ * Returns a GraphQLFieldConfigArgumentMap appropriate to include on a field | ||
*/ | ||
export const backwardConnectionArgs: GraphQLFieldConfigArgumentMap & | ||
BackwardConnectionArgs; | ||
export declare const backwardConnectionArgs: GraphQLFieldConfigArgumentMap; | ||
/** | ||
@@ -42,11 +25,7 @@ * Returns a GraphQLFieldConfigArgumentMap appropriate to include on a field | ||
*/ | ||
export const connectionArgs: GraphQLFieldConfigArgumentMap & | ||
ForwardConnectionArgs & | ||
BackwardConnectionArgs; | ||
export declare const connectionArgs: GraphQLFieldConfigArgumentMap; | ||
/** | ||
* A type alias for cursors in this implementation. | ||
*/ | ||
export type ConnectionCursor = string; | ||
export declare type ConnectionCursor = string; | ||
/** | ||
@@ -61,12 +40,10 @@ * A type describing the arguments a connection field receives in GraphQL. | ||
} | ||
export interface ConnectionConfig { | ||
name?: string; | ||
nodeType: GraphQLNamedType | GraphQLNonNull<GraphQLNamedType>; | ||
nodeType: GraphQLNamedOutputType | GraphQLNonNull<GraphQLNamedOutputType>; | ||
resolveNode?: GraphQLFieldResolver<any, any>; | ||
resolveCursor?: GraphQLFieldResolver<any, any>; | ||
edgeFields?: Thunk<GraphQLFieldConfigMap<any, any>>; | ||
connectionFields?: Thunk<GraphQLFieldConfigMap<any, any>>; | ||
edgeFields?: ThunkObjMap<GraphQLFieldConfig<any, any>>; | ||
connectionFields?: ThunkObjMap<GraphQLFieldConfig<any, any>>; | ||
} | ||
export interface GraphQLConnectionDefinitions { | ||
@@ -76,3 +53,2 @@ edgeType: GraphQLObjectType; | ||
} | ||
/** | ||
@@ -82,6 +58,5 @@ * Returns a GraphQLObjectType for a connection with the given name, | ||
*/ | ||
export function connectionDefinitions( | ||
export declare function connectionDefinitions( | ||
config: ConnectionConfig, | ||
): GraphQLConnectionDefinitions; | ||
/** | ||
@@ -94,3 +69,2 @@ * A type designed to be exposed as a `Connection` over GraphQL. | ||
} | ||
/** | ||
@@ -103,3 +77,2 @@ * A type designed to be exposed as a `Edge` over GraphQL. | ||
} | ||
/** | ||
@@ -106,0 +79,0 @@ * A type designed to be exposed as `PageInfo` over GraphQL. |
@@ -59,7 +59,2 @@ 'use strict'; | ||
function resolveMaybeThunk(thingOrThunk) { | ||
return typeof thingOrThunk === 'function' // $FlowFixMe[incompatible-use] - if it's a function, we assume a thunk without arguments | ||
? thingOrThunk() | ||
: thingOrThunk; | ||
} | ||
/** | ||
@@ -69,3 +64,2 @@ * Returns a GraphQLObjectType for a connection with the given name, | ||
*/ | ||
function connectionDefinitions(config) { | ||
@@ -96,3 +90,3 @@ var _config$name; | ||
}, | ||
...resolveMaybeThunk( | ||
...(0, _graphql.resolveObjMapThunk)( | ||
(_config$edgeFields = config.edgeFields) !== null && | ||
@@ -121,3 +115,3 @@ _config$edgeFields !== void 0 | ||
}, | ||
...resolveMaybeThunk( | ||
...(0, _graphql.resolveObjMapThunk)( | ||
(_config$connectionFie = config.connectionFields) !== null && | ||
@@ -124,0 +118,0 @@ _config$connectionFie !== void 0 |
@@ -1,2 +0,1 @@ | ||
// Types for creating connection types in the schema | ||
export type { | ||
@@ -6,7 +5,7 @@ Connection, | ||
ConnectionCursor, | ||
ConnectionConfig, | ||
GraphQLConnectionDefinitions, | ||
Edge, | ||
PageInfo, | ||
} from './connection/connection'; | ||
// Helpers for creating connection types in the schema | ||
export { | ||
@@ -18,4 +17,2 @@ backwardConnectionArgs, | ||
} from './connection/connection'; | ||
// Helpers for creating connections from arrays | ||
export { | ||
@@ -31,13 +28,5 @@ connectionFromArray, | ||
} from './connection/arrayConnection'; | ||
// Helper for creating mutations with client mutation IDs | ||
export { mutationWithClientMutationId } from './mutation/mutation'; | ||
// Helper for creating node definitions | ||
export { nodeDefinitions } from './node/node'; | ||
// Helper for creating plural identifying root fields | ||
export { pluralIdentifyingRootField } from './node/plural'; | ||
// Utilities for creating global IDs in systems that don't have them. | ||
export { fromGlobalId, globalIdField, toGlobalId } from './node/node'; |
import type { | ||
GraphQLFieldConfig, | ||
GraphQLFieldExtensions, | ||
GraphQLInputFieldConfigMap, | ||
GraphQLFieldConfigMap, | ||
GraphQLInputFieldConfig, | ||
GraphQLResolveInfo, | ||
Thunk, | ||
ThunkObjMap, | ||
} from 'graphql'; | ||
type MutationFn = (object: any, ctx: any, info: GraphQLResolveInfo) => unknown; | ||
declare type MutationFn = ( | ||
object: any, | ||
ctx: any, | ||
info: GraphQLResolveInfo, | ||
) => unknown; | ||
/** | ||
@@ -31,7 +32,6 @@ * A description of a mutation consumable by mutationWithClientMutationId | ||
extensions?: GraphQLFieldExtensions<any, any>; | ||
inputFields: Thunk<GraphQLInputFieldConfigMap>; | ||
outputFields: Thunk<GraphQLFieldConfigMap<any, any>>; | ||
inputFields: ThunkObjMap<GraphQLInputFieldConfig>; | ||
outputFields: ThunkObjMap<GraphQLFieldConfig<any, any>>; | ||
mutateAndGetPayload: MutationFn; | ||
} | ||
/** | ||
@@ -41,4 +41,5 @@ * Returns a GraphQLFieldConfig for the mutation described by the | ||
*/ | ||
export function mutationWithClientMutationId( | ||
export declare function mutationWithClientMutationId( | ||
config: MutationConfig, | ||
): GraphQLFieldConfig<any, any>; | ||
): GraphQLFieldConfig<unknown, unknown>; | ||
export {}; |
@@ -10,29 +10,3 @@ 'use strict'; | ||
var _isPromise = _interopRequireDefault(require('graphql/jsutils/isPromise')); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : { default: obj }; | ||
} | ||
function resolveMaybeThunk(thingOrThunk) { | ||
return typeof thingOrThunk === 'function' // $FlowFixMe[incompatible-use] - if it's a function, we assume a thunk without arguments | ||
? thingOrThunk() | ||
: thingOrThunk; | ||
} | ||
/** | ||
* A description of a mutation consumable by mutationWithClientMutationId | ||
* to create a GraphQLFieldConfig for that mutation. | ||
* | ||
* The inputFields and outputFields should not include `clientMutationId`, | ||
* as this will be provided automatically. | ||
* | ||
* An input object will be created containing the input fields, and an | ||
* object will be created containing the output fields. | ||
* | ||
* mutateAndGetPayload will receive an Object with a key for each | ||
* input field, and it should return an Object with a key for each | ||
* output field. It may return synchronously, or return a Promise. | ||
*/ | ||
/** | ||
* Returns a GraphQLFieldConfig for the mutation described by the | ||
@@ -45,3 +19,3 @@ * provided MutationConfig. | ||
const augmentedInputFields = () => ({ | ||
...resolveMaybeThunk(inputFields), | ||
...(0, _graphql.resolveObjMapThunk)(inputFields), | ||
clientMutationId: { | ||
@@ -53,3 +27,3 @@ type: _graphql.GraphQLString, | ||
const augmentedOutputFields = () => ({ | ||
...resolveMaybeThunk(outputFields), | ||
...(0, _graphql.resolveObjMapThunk)(outputFields), | ||
clientMutationId: { | ||
@@ -82,3 +56,3 @@ type: _graphql.GraphQLString, | ||
if ((0, _isPromise.default)(payload)) { | ||
if (isPromiseLike(payload)) { | ||
return payload.then(injectClientMutationId); | ||
@@ -91,3 +65,3 @@ } | ||
if (typeof data === 'object' && data !== null) { | ||
// $FlowFixMe[cannot-write] It's bad idea to mutate data but we need to pass clientMutationId somehow. Maybe in future we figure out better solution satisfying all our test cases. | ||
// @ts-expect-error FIXME It's bad idea to mutate data but we need to pass clientMutationId somehow. Maybe in future we figure out better solution satisfying all our test cases. | ||
data.clientMutationId = clientMutationId; | ||
@@ -100,2 +74,10 @@ } | ||
}; | ||
} // FIXME: Temporary until graphql-js resolves this issue | ||
// See, https://github.com/graphql/graphql-js/pull/3243#issuecomment-919510590 | ||
function isPromiseLike(value) { | ||
return ( | ||
typeof (value === null || value === void 0 ? void 0 : value.then) === | ||
'function' | ||
); | ||
} |
@@ -0,14 +1,12 @@ | ||
import { GraphQLInterfaceType } from 'graphql'; | ||
import type { | ||
GraphQLFieldConfig, | ||
GraphQLInterfaceType, | ||
GraphQLResolveInfo, | ||
GraphQLTypeResolver, | ||
} from 'graphql'; | ||
interface GraphQLNodeDefinitions<TContext> { | ||
nodeInterface: GraphQLInterfaceType; | ||
nodeField: GraphQLFieldConfig<any, TContext>; | ||
nodesField: GraphQLFieldConfig<any, TContext>; | ||
nodeField: GraphQLFieldConfig<unknown, TContext>; | ||
nodesField: GraphQLFieldConfig<unknown, TContext>; | ||
} | ||
/** | ||
@@ -24,3 +22,3 @@ * Given a function to map from an ID to an underlying object, and a function | ||
*/ | ||
export function nodeDefinitions<TContext>( | ||
export declare function nodeDefinitions<TContext>( | ||
fetchById: ( | ||
@@ -33,3 +31,2 @@ id: string, | ||
): GraphQLNodeDefinitions<TContext>; | ||
interface ResolvedGlobalId { | ||
@@ -39,3 +36,2 @@ type: string; | ||
} | ||
/** | ||
@@ -45,4 +41,3 @@ * Takes a type name and an ID specific to that type name, and returns a | ||
*/ | ||
export function toGlobalId(type: string | number, id: string): string; | ||
export declare function toGlobalId(type: string, id: string | number): string; | ||
/** | ||
@@ -52,4 +47,3 @@ * Takes the "global ID" created by toGlobalID, and returns the type name and ID | ||
*/ | ||
export function fromGlobalId(globalId: string): ResolvedGlobalId; | ||
export declare function fromGlobalId(globalId: string): ResolvedGlobalId; | ||
/** | ||
@@ -61,3 +55,3 @@ * Creates the configuration for an id field on a node, using `toGlobalId` to | ||
*/ | ||
export function globalIdField<TContext>( | ||
export declare function globalIdField<TContext>( | ||
typeName?: string, | ||
@@ -70,1 +64,2 @@ idFetcher?: ( | ||
): GraphQLFieldConfig<any, TContext>; | ||
export {}; |
@@ -7,3 +7,2 @@ import type { | ||
} from 'graphql'; | ||
interface PluralIdentifyingRootFieldConfig { | ||
@@ -20,5 +19,5 @@ argName: string; | ||
} | ||
export function pluralIdentifyingRootField( | ||
export declare function pluralIdentifyingRootField( | ||
config: PluralIdentifyingRootFieldConfig, | ||
): GraphQLFieldConfig<any, any>; | ||
): GraphQLFieldConfig<unknown, unknown>; | ||
export {}; |
{ | ||
"name": "graphql-relay", | ||
"version": "0.9.0", | ||
"version": "0.10.0", | ||
"description": "A library to help construct a graphql-js server supporting react-relay.", | ||
"license": "MIT", | ||
"main": "index", | ||
"types": "index.d.ts", | ||
"typesVersions": { | ||
">=4.1.0": { | ||
"*": [ | ||
"*" | ||
] | ||
}, | ||
"*": { | ||
"*": [ | ||
"NotSupportedTSVersion.d.ts" | ||
] | ||
} | ||
}, | ||
"sideEffects": false, | ||
@@ -24,4 +35,7 @@ "homepage": "https://github.com/graphql/graphql-relay-js", | ||
"peerDependencies": { | ||
"graphql": "^15.5.3" | ||
"graphql": "^16.2.0" | ||
}, | ||
"publishConfig": { | ||
"tag": "latest" | ||
} | ||
} | ||
} |
@@ -170,3 +170,3 @@ # Relay Library for GraphQL.js | ||
This library is written in ES6 and uses [Babel](https://babeljs.io/) for ES5 transpilation and [Flow](https://flow.org/) for type safety. Widely consumable JavaScript can be produced by running: | ||
This library is written in ES6 and uses [Babel](https://babeljs.io/) for ES5 transpilation and [TypeScript](https://www.typescriptlang.org/) for type safety. Widely consumable JavaScript can be produced by running: | ||
@@ -173,0 +173,0 @@ ```sh |
@@ -111,2 +111,3 @@ 'use strict'; | ||
for (const utfChar of input) { | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
const code = utfChar.codePointAt(0); | ||
@@ -141,3 +142,3 @@ | ||
if ((a & 0x80) === 0) { | ||
result += String.fromCodePoint(a); | ||
result += fromCodePoint(a); | ||
continue; | ||
@@ -149,3 +150,3 @@ } | ||
if ((a & 0xe0) === 0xc0) { | ||
result += String.fromCodePoint(((a & 0x1f) << 6) | (b & 0x3f)); | ||
result += fromCodePoint(((a & 0x1f) << 6) | (b & 0x3f)); | ||
continue; | ||
@@ -157,3 +158,3 @@ } | ||
if ((a & 0xf0) === 0xe0) { | ||
result += String.fromCodePoint( | ||
result += fromCodePoint( | ||
((a & 0x0f) << 12) | ((b & 0x3f) << 6) | (c & 0x3f), | ||
@@ -165,3 +166,3 @@ ); | ||
const d = input[i++]; | ||
result += String.fromCodePoint( | ||
result += fromCodePoint( | ||
((a & 0x07) << 18) | ((b & 0x3f) << 12) | ((c & 0x3f) << 6) | (d & 0x3f), | ||
@@ -173,1 +174,15 @@ ); | ||
} | ||
function fromCodePoint(code) { | ||
if (code > 0x10ffff) { | ||
/* | ||
* Previously we used Node's API for parsing Base64 and following code | ||
* Buffer.from(i, 'base64').toString('utf8') | ||
* That silently ignored incorrect input and returned empty string instead | ||
* Let's keep this behaviour for a time being and hopefully fix it in the future. | ||
*/ | ||
return ''; | ||
} | ||
return String.fromCodePoint(code); | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44719
18
1047