جافا سكريبت - خطأ: خطأ في الشبكة: خطأ عند كتابة النتيجة إلى المخزن للاستعلام:


الحصول على هذا الخطأ من أبولو:

core.js:14576 ERROR Error: Network error: Error writing result to store for query:
 {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"AdditionalServices"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"vendorID"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ID"}}},"directives":[]}],"directives":[],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"vendor"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"vendorID"}}}],"directives":[],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"services"},"name":{"kind":"Name","value":"products"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"productTypes"},"value":{"kind":"EnumValue","value":"service"}}],"directives":[],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"nodes"},"arguments":[],"directives":[],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"},"arguments":[],"directives":[]},{"kind":"Field","name":{"kind":"Name","value":"isActive"},"arguments":[],"directives":[]},{"kind":"Field","name":{"kind":"Name","value":"cartSection"},"arguments":[],"directives":[],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"},"arguments":[],"directives":[]},{"kind":"Field","name":{"kind":"Name","value":"name"},"arguments":[],"directives":[]},{"kind":"Field","name":{"kind":"Name","value":"__typename"}}]}},{"kind":"Field","name":{"kind":"Name","value":"description"},"arguments":[],"directives":[]},{"kind":"Field","name":{"kind":"Name","value":"imageUrl"},"arguments":[],"directives":[]},{"kind":"Field","name":{"kind":"Name","value":"shortDescription"},"arguments":[],"directives":[]},{"kind":"Field","name":{"kind":"Name","value":"name"},"arguments":[],"directives":[]},{"kind":"Field","name":{"kind":"Name","value":"__typename"}}]}},{"kind":"Field","name":{"kind":"Name","value":"__typename"}}]}},{"kind":"Field","name":{"kind":"Name","value":"__typename"}}]}}]}}],"loc":{"start":0,"end":372}}
Store error: the application attempted to write an object with no provided id but the store already contains an id of Restaurant:200 for this object. The selectionSet that was trying to be written is:
{"kind":"Field","name":{"kind":"Name","value":"vendor"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"vendorID"}}}],"directives":[],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"services"},"name":{"kind":"Name","value":"products"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"productTypes"},"value":{"kind":"EnumValue","value":"service"}}],"directives":[],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"nodes"},"arguments":[],"directives":[],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"},"arguments":[],"directives":[]},{"kind":"Field","name":{"kind":"Name","value":"isActive"},"arguments":[],"directives":[]},{"kind":"Field","name":{"kind":"Name","value":"cartSection"},"arguments":[],"directives":[],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"},"arguments":[],"directives":[]},{"kind":"Field","name":{"kind":"Name","value":"name"},"arguments":[],"directives":[]},{"kind":"Field","name":{"kind":"Name","value":"__typename"}}]}},{"kind":"Field","name":{"kind":"Name","value":"description"},"arguments":[],"directives":[]},{"kind":"Field","name":{"kind":"Name","value":"imageUrl"},"arguments":[],"directives":[]},{"kind":"Field","name":{"kind":"Name","value":"shortDescription"},"arguments":[],"directives":[]},{"kind":"Field","name":{"kind":"Name","value":"name"},"arguments":[],"directives":[]},{"kind":"Field","name":{"kind":"Name","value":"__typename"}}]}},{"kind":"Field","name":{"kind":"Name","value":"__typename"}}]}},{"kind":"Field","name":{"kind":"Name","value":"__typename"}}]}}
    at new ApolloError (ApolloError.js:25)
    at QueryManager.js:276
    at QueryManager.js:638
    at Array.forEach (<anonymous>)
    at QueryManager.js:637
    at Map.forEach (<anonymous>)
    at QueryManager.push../node_modules/apollo-client/core/QueryManager.js.QueryManager.broadcastQueries (QueryManager.js:632)
    at QueryManager.js:226
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:391)
    at Object.onInvoke (core.js:16135)

هذا هو الكود الذي يجعل هذا يحدث:

   this.restaurantID$.pipe(
      takeUntil(this._ngOnDestroy)
      )
      .subscribe((restaurantID) => {
        this.additionalServicesQuery$.next(this._apollo
          .watchQuery<AdditionalServices>({
            query: AdditionalServicesQuery,
            variables: { vendorID: restaurantID }
          }));
      });

    const loadAdditionalServicesData = this.additionalServicesQuery$
      .pipe(
        takeUntil(this._ngOnDestroy),
        filter((query) => !!query),
        switchMap((query) => query.valueChanges), // This is the switchMap that makes it happen
        takeUntil(this._ngOnDestroy),
        map((response) => response.data.vendor.services.nodes)
      );

هناك SwitchMap قمت بالتعليق عليه، إذا تم إزالته، لا يحدث الخطأ. لا أستطيع فهم ما يجري.

استعلام:

export const AdditionalServicesQuery = gql`
  query AdditionalServices(
    $vendorID: ID!
  ) {
    vendor(
      id: $vendorID
    ) {
      services: products (productTypes: service) {
        nodes {
          id
          isActive
          cartSection {
            id
            name
          }
          description
          imageUrl
          shortDescription
          name
        }
      }
    }
  }
`;

تحديث:

تم إضافة المعرف إلى الاستعلام، ومع ذلك، نفس المشكلة

export const AdditionalServicesQuery = gql`
  query AdditionalServices(
    $vendorID: ID!
  ) {
    vendor(
      id: $vendorID
    ) {
      services: products (productTypes: service) {
        id
        nodes {
          id
          isActive
          cartSection {
            id
            name
          }
          description
          imageUrl
          shortDescription
          name
        }
      }
    }
  }
`;

الإجابة رقم 1

وفقًا لذلك الخطأ، تحتاج إلى إضافة حقل id (أو حقل _id، أيهما موجود) إلى مجموعة الاختيار لحقل vendor. يبدو أنك لديك بالفعل استعلام آخر يعيد كائنات من النوع Restaurant، وقد شمل ذلك الاستعلام الـ id وتمت معالجته بشكل صحيح. لن يتمكن Apollo من دمج كائنات Restaurant الفردية من كلا الاستعلامين ما لم يتم تضمين id.

export const AdditionalServicesQuery = gql`
  query AdditionalServices(
    $vendorID: ID!
  ) {
    vendor(
      id: $vendorID
    ) {
      id # <----------------------------------------- ADD ME
      services: products (productTypes: service) {
        nodes {
          id
          isActive
          cartSection {
            id
            name
          }
          description
          imageUrl
          shortDescription
          name
        }
      }
    }
  }
`;