Skip to content

Commit

Permalink
Cleanup AVOID_CYCLES_IN_RESOLVER_NOTIFICATION
Browse files Browse the repository at this point in the history
Differential Revision: D65505484

fbshipit-source-id: de45203ed475f9583c3d0b2a3d81776990ebd26f
  • Loading branch information
captbaritone authored and facebook-github-bot committed Nov 8, 2024
1 parent 1a00c63 commit 2c3b915
Show file tree
Hide file tree
Showing 10 changed files with 5,442 additions and 5,567 deletions.
3,268 changes: 1,619 additions & 1,649 deletions packages/react-relay/__tests__/LiveResolvers-test.js

Large diffs are not rendered by default.

655 changes: 322 additions & 333 deletions packages/react-relay/__tests__/RelayResolverInterface-test.js

Large diffs are not rendered by default.

1,248 changes: 613 additions & 635 deletions packages/react-relay/__tests__/RelayResolverModel-test.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1,008 changes: 499 additions & 509 deletions packages/react-relay/__tests__/RelayResolvers-withOutputType-test.js

Large diffs are not rendered by default.

314 changes: 154 additions & 160 deletions packages/relay-runtime/store/__tests__/ClientEdgeToClientObject-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import type {ClientEdgeToClientObjectTest3Query$data} from './__generated__/ClientEdgeToClientObjectTest3Query.graphql';

const {RelayFeatureFlags, commitLocalUpdate} = require('relay-runtime');
const {commitLocalUpdate} = require('relay-runtime');
const RelayNetwork = require('relay-runtime/network/RelayNetwork');
const {graphql} = require('relay-runtime/query/GraphQLTag');
const RelayModernEnvironment = require('relay-runtime/store/RelayModernEnvironment');
Expand All @@ -30,66 +30,62 @@ const {
disallowConsoleErrors();
disallowWarnings();

describe.each([true, false])(
'AVOID_CYCLES_IN_RESOLVER_NOTIFICATION is %p',
avoidCycles => {
RelayFeatureFlags.AVOID_CYCLES_IN_RESOLVER_NOTIFICATION = avoidCycles;
test('Can read a deep portion of the schema that is backed by client edges to client objects.', () => {
const source = RelayRecordSource.create({
'client:root': {
__id: 'client:root',
__typename: '__Root',
me: {__ref: '1'},
},
'1': {
__id: '1',
id: '1',
__typename: 'User',
birthdate: {__ref: '2'},
},
'2': {
__id: '2',
id: '2',
__typename: 'Date',
day: 11,
month: 3,
},
});
const FooQuery = graphql`
query ClientEdgeToClientObjectTest1Query {
me {
astrological_sign {
test('Can read a deep portion of the schema that is backed by client edges to client objects.', () => {
const source = RelayRecordSource.create({
'client:root': {
__id: 'client:root',
__typename: '__Root',
me: {__ref: '1'},
},
'1': {
__id: '1',
id: '1',
__typename: 'User',
birthdate: {__ref: '2'},
},
'2': {
__id: '2',
id: '2',
__typename: 'Date',
day: 11,
month: 3,
},
});
const FooQuery = graphql`
query ClientEdgeToClientObjectTest1Query {
me {
astrological_sign {
__id
name
house
opposite {
__id
name
house
opposite {
__id
name
house
opposite {
__id
name
house
opposite {
__id
name
}
}
}
}
}
`;
}
}
`;

const operation = createOperationDescriptor(FooQuery, {});
const store = new RelayModernStore(source, {
gcReleaseBufferSize: 0,
});
const operation = createOperationDescriptor(FooQuery, {});
const store = new RelayModernStore(source, {
gcReleaseBufferSize: 0,
});

const environment = new RelayModernEnvironment({
network: RelayNetwork.create(jest.fn()),
store,
});
const environment = new RelayModernEnvironment({
network: RelayNetwork.create(jest.fn()),
store,
});

// $FlowFixMe[unclear-type] - lookup() doesn't have the nice types of reading a fragment through the actual APIs:
const {me}: any = environment.lookup(operation.fragment).data;
// $FlowFixMe[unclear-type] - lookup() doesn't have the nice types of reading a fragment through the actual APIs:
const {me}: any = environment.lookup(operation.fragment).data;

expect(me).toMatchInlineSnapshot(`
expect(me).toMatchInlineSnapshot(`
Object {
"astrological_sign": Object {
"__id": "client:AstrologicalSign:Pisces",
Expand All @@ -107,42 +103,42 @@ describe.each([true, false])(
},
}
`);
});
});

test('Can read a plural client edge to list of client defined types', () => {
const source = RelayRecordSource.create({
'client:root': {
__id: 'client:root',
__typename: '__Root',
me: {__ref: '1'},
},
'1': {
__id: '1',
id: '1',
__typename: 'User',
},
});
const FooQuery = graphql`
query ClientEdgeToClientObjectTest2Query {
all_astrological_signs {
name
}
}
`;
test('Can read a plural client edge to list of client defined types', () => {
const source = RelayRecordSource.create({
'client:root': {
__id: 'client:root',
__typename: '__Root',
me: {__ref: '1'},
},
'1': {
__id: '1',
id: '1',
__typename: 'User',
},
});
const FooQuery = graphql`
query ClientEdgeToClientObjectTest2Query {
all_astrological_signs {
name
}
}
`;

const operation = createOperationDescriptor(FooQuery, {});
const store = new RelayModernStore(source, {
gcReleaseBufferSize: 0,
});
const operation = createOperationDescriptor(FooQuery, {});
const store = new RelayModernStore(source, {
gcReleaseBufferSize: 0,
});

const environment = new RelayModernEnvironment({
network: RelayNetwork.create(jest.fn()),
store,
});
const environment = new RelayModernEnvironment({
network: RelayNetwork.create(jest.fn()),
store,
});

const {data} = environment.lookup(operation.fragment);
const {data} = environment.lookup(operation.fragment);

expect(data).toMatchInlineSnapshot(`
expect(data).toMatchInlineSnapshot(`
Object {
"all_astrological_signs": Array [
Object {
Expand Down Expand Up @@ -184,90 +180,88 @@ describe.each([true, false])(
],
}
`);
});
});

test('Uses an existing client record if it already exists', () => {
const source = RelayRecordSource.create({
'client:root': {
__id: 'client:root',
__typename: '__Root',
me: {__ref: '1'},
},
'1': {
__id: '1',
id: '1',
__typename: 'User',
birthdate: {__ref: '2'},
},
'2': {
__id: '2',
id: '2',
__typename: 'Date',
day: 11,
month: 3,
},
});
test('Uses an existing client record if it already exists', () => {
const source = RelayRecordSource.create({
'client:root': {
__id: 'client:root',
__typename: '__Root',
me: {__ref: '1'},
},
'1': {
__id: '1',
id: '1',
__typename: 'User',
birthdate: {__ref: '2'},
},
'2': {
__id: '2',
id: '2',
__typename: 'Date',
day: 11,
month: 3,
},
});

const FooQuery = graphql`
query ClientEdgeToClientObjectTest3Query {
me {
astrological_sign {
__id
name
notes
}
}
const FooQuery = graphql`
query ClientEdgeToClientObjectTest3Query {
me {
astrological_sign {
__id
name
notes
}
`;
}
}
`;

const operation = createOperationDescriptor(FooQuery, {});
const liveStore = new RelayModernStore(source, {
gcReleaseBufferSize: 0,
});
const operation = createOperationDescriptor(FooQuery, {});
const liveStore = new RelayModernStore(source, {
gcReleaseBufferSize: 0,
});

const environment = new RelayModernEnvironment({
network: RelayNetwork.create(jest.fn()),
store: liveStore,
});
const environment = new RelayModernEnvironment({
network: RelayNetwork.create(jest.fn()),
store: liveStore,
});

const data: ClientEdgeToClientObjectTest3Query$data = (environment.lookup(
operation.fragment,
// $FlowFixMe[unclear-type] - lookup() doesn't have the nice types of reading a fragment through the actual APIs:
).data: any);
const data: ClientEdgeToClientObjectTest3Query$data = (environment.lookup(
operation.fragment,
// $FlowFixMe[unclear-type] - lookup() doesn't have the nice types of reading a fragment through the actual APIs:
).data: any);

expect(data).toEqual({
me: {
astrological_sign: {
__id: 'client:AstrologicalSign:Pisces',
name: 'Pisces',
notes: undefined,
},
},
});
expect(data).toEqual({
me: {
astrological_sign: {
__id: 'client:AstrologicalSign:Pisces',
name: 'Pisces',
notes: undefined,
},
},
});

commitLocalUpdate(environment, store => {
const id = data.me?.astrological_sign?.__id;
if (id == null) {
throw new Error('Expected to get an id');
}
const sign = store.get(id);
if (sign == null) {
throw new Error('Tried to reference a non-existent sign');
}
sign.setValue('This is a cool note.', 'notes');
});
commitLocalUpdate(environment, store => {
const id = data.me?.astrological_sign?.__id;
if (id == null) {
throw new Error('Expected to get an id');
}
const sign = store.get(id);
if (sign == null) {
throw new Error('Tried to reference a non-existent sign');
}
sign.setValue('This is a cool note.', 'notes');
});

const {data: newData} = environment.lookup(operation.fragment);
const {data: newData} = environment.lookup(operation.fragment);

expect(newData).toEqual({
me: {
astrological_sign: {
__id: 'client:AstrologicalSign:Pisces',
name: 'Pisces',
notes: 'This is a cool note.',
},
},
});
});
},
);
expect(newData).toEqual({
me: {
astrological_sign: {
__id: 'client:AstrologicalSign:Pisces',
name: 'Pisces',
notes: 'This is a cool note.',
},
},
});
});
Loading

0 comments on commit 2c3b915

Please sign in to comment.