标签: resolver

Angular 2:共享相同解析器的兄弟姐妹子路由

我想弄清楚是否有一种更优化的方式在两个同级儿童路线之间共享相同的解析器.以下是路线与解析器相关的示例.

import { CommonModule } from '@angular/common';
import { RouterModule } from '@angular/router';
import { NgModule } from '@angular/core';
export const routes = [{
        path: '',
        component: parentComponent,
        canActivate: [AuthGuard],
        resolve: {
            someData: someDataResolver
        },
        children: [
            { path: '', redirectTo: '0', pathMatch: 'full' },
            { path: '0', 
                component: someComponent1,
                resolve: {
                    someData1: someData1Resolver,
                    someData2: someData2Resolver,
                }
            },
            { path: '2', 
                component: someComponent2,
                resolve: {
                    someData2: someData2Resolver
                }
            }
            ... a bunch more children routes/components with resolvers

        ]
    }]
Run Code Online (Sandbox Code Playgroud)

现在,我正在重复每个儿童路线的解析器呼叫,我认为这不是最佳的.有谁知道是否有更好的方法来共享共享兄弟儿童解析器的数据?我考虑将数据从重复的解析器设置为共享服务,然后另一个子兄弟路由将从服务访问数据(而不是在解析器中进行另一个api调用).还有其他更优化的解决方案吗?

routes resolver angular

4
推荐指数
1
解决办法
2279
查看次数

解析器上带有参数的解析器

所以我在角度5中实现了一个解析器:

@Injectable()
    export class AppResolver implements Resolve<MyComplexObject []> {
        constructor(private myService: MyService) {

        }
        resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<MyComplexObject[]> {
            return this.myService.getMyApi(myOption); // my option is a string
        }
    }
Run Code Online (Sandbox Code Playgroud)

现在,myOption是一个硬编码的字符串,我想更改它

在我的路由模块中,我有:

resolve: {
        myResolver: AppResolver
      }
Run Code Online (Sandbox Code Playgroud)

我想也许在这里我应该指定myOption字符串的值,但是如何?

或更好的地方,我实际上称为解析器

this.route.data.map(data => data.myResolver).subscribe(
      result => {
        // do something with the result (specify who the myOption is?? How)
    });
Run Code Online (Sandbox Code Playgroud)

该参数不一定在浏览器中可见:

它将是网址的一部分:/.../.../myString/ ..

但是它不是由param引入的:url:/..&myParam=paramValue

所以我不能使用myParam从网址中识别它并替换它

resolver angular

4
推荐指数
1
解决办法
2690
查看次数

Spring XML View Resolver Conifguration

我试图使用spring-mvc将一些模型数据输出到pdf.它不起作用,我想知道是否有人可以提供一些建议.

我有一个spring-servlet.xml文件,其中包含以下内容:

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="order" value="1"/>
    <property name="prefix" value="/WEB-INF/view/"/>
    <property name="suffix" value=".jsp"/>
</bean>

<bean id="xmlViewResolver" class="org.springframework.web.servlet.view.XmlViewResolver">
    <property name="order" value="2"/>
    <property name="location">
        <value>/WEB-INF/spring-pdf-views.xml</value>
    </property>
</bean>
Run Code Online (Sandbox Code Playgroud)

在spring-pdf-views.xml文件中,我有:

<bean id="MyPDF" class="com.example.MyPDFView"/>
Run Code Online (Sandbox Code Playgroud)

这是我的MyPDFView类:

public class MyPDFView extends AbstractPdfView {

    @Override
    protected void buildPdfDocument(Map<String, Object> model, Document document, PdfWriter writer, 
            HttpServletRequest request, HttpServletResponse response) throws Exception {

        @SuppressWarnings("unchecked")
        Map<String, String> data = (Map<String, String>) model.get("modelData");

        Table table = new Table(2);
        table.addCell("Date");
        table.addCell("Name");
        table.addCell(data.get("modelData.dateValue"));
        table.addCell(data.get("modelData.nameValue"));

        document.add(table);
    }
}
Run Code Online (Sandbox Code Playgroud)

}

最后在我的控制器中我有:

@RequestMapping(value="/pdfInformation", method=RequestMethod.POST)
public ModelAndView …
Run Code Online (Sandbox Code Playgroud)

java xml spring view resolver

3
推荐指数
1
解决办法
8559
查看次数

AutoMapper - 将参数传递给自定义解析器奇怪的行为

虽然我对AutoMapper比较陌生,但我正在开发一个小项目中使用它.我之前从未遇到过使用它的问题,但现在我面临一些将参数传递给Custom Resolver的奇怪行为.

这是一个场景:我从我的存储库中获取一个消息列表,然后将它们映射到它的前端友好版本.没什么好看的,只是对象之间的一些正常映射.我在该前端对象中有一个字段,告诉某个用户是否已经为该消息投票,这就是我正在使用自定义解析器(这是第二个"ForMember"):

    public List<SupportMessageUi> GetAllVisible(string userId)
    {
        Mapper.CreateMap<SupportMessage, SupportMessageUi>()
              .ForMember(dest => dest.Votes,
                         opt => opt.ResolveUsing<SupportMessageVotesResolver>())
              .ForMember(dest => dest.UserVoted,
                         opt => opt.ResolveUsing<SupportMessagesUserVotedResolver>()
                                   .ConstructedBy(() => new SupportMessagesUserVotedResolver(userId)));

        var messages = _unitOfWork.MessagesRepository.Get(m => m.Visible);

        var messagesUi = Mapper.Map<List<SupportMessageUi>>(messages);

        return messagesUi;
    }
Run Code Online (Sandbox Code Playgroud)


我在Web服务上调用这个方法,问题是:第一次调用webservice(使用webservice控制台)时,它运行完美.例如,如果我通过'555'作为userId我使用正确的值来获取此方法:

在此输入图像描述


在Custom Resolver中,值正确传递给构造函数: 在此输入图像描述


返回的结果是正确的.问题接下来.第二次调用服务时,传递一个不同的参数(这次是'666'),获取Custom Resolver构造函数的参数是旧参数('555').这就是我的意思:

在映射对象之前,我们可以看到传递给构造函数的值是正确的('666'): 在此输入图像描述


但当它到达解析器的构造函数时,值是错误的,并且是旧的('555'): 在此输入图像描述


对服务的所有后续调用都使用Custom Resolver构造函数('555')中的原始值,与我传递给服务的值无关(如果我从另一个浏览器进行调用,也会发生这种情况).如果我关闭服务器并重新启动它,我可以传递一个新参数(将在所有其他调用中使用,直到我再次关闭它).

对于为什么会发生这种情况的任何想法?

parameter-passing resolver automapper

3
推荐指数
2
解决办法
8356
查看次数

全局二级索引上的AppSync查询

我正在尝试从GSI获取记录,但遇到了麻烦。

API架构:

type DriverInfos {
    id: String!
    status: Int
    lastLat: Float
    lastLng: Float
    idDriver: String # GSI
}

type Query {
    getDriverInfosByDriver(idDriver: String): DriverInfos
}
Run Code Online (Sandbox Code Playgroud)

解析器:

{
    "version" : "2017-02-28",
    "operation" : "Query",
    "index" : "idDriver-index",
    "query" : {
        ## Provide a query expression. **
        "expression": "#idDriver = :idDriver",
        "expressionNames" : {
            "#idDriver" : "idDriver"
        },
        "expressionValues" : {
            ":idDriver" : {
                "S" : "${ctx.args.idDriver}"        
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

查询:

query getDriverInfosByDriver{
  getDriverInfosByDriver(idDriver: "1") 
    {    
      idDriver
      status
      lastLat
      lastLng 
    } …
Run Code Online (Sandbox Code Playgroud)

resolver amazon-web-services graphql react-native aws-appsync

3
推荐指数
1
解决办法
1335
查看次数

如何使用AppSync解析器和Aurora将可选字段插入为null?

我有一个可选的String字段notes,有时为空。如果为空,我想插入null,否则我想插入字符串。

这是我的解析器-

{
    "version" : "2017-02-28",
    "operation": "Invoke",
        #set($id = $util.autoId())
        #set($notes = $util.defaultIfNullOrEmpty($context.arguments.notes, 'null'))

        "payload": {
          "sql":"INSERT INTO things VALUES ('$id', :NOTES)",
          "variableMapping": {
            ":NOTES" : $notes
          },
          "responseSQL": "SELECT * FROM things WHERE id = '$id'"
        }
Run Code Online (Sandbox Code Playgroud)

}

有了这个graphql

mutation CreateThing{
  createThing() {
    id
    notes
  }
}
Run Code Online (Sandbox Code Playgroud)

我得到-

{
  "data": {
    "createRoll": {
      "id": "6af68989-0bdc-44e2-8558-aeb4c8418e93",
     "notes": "null"
   }
 }
Run Code Online (Sandbox Code Playgroud)

}

当我真的想要没有引号的null时

有了这个graphql-

mutation CreateThing{
  createThing(notes: "Here are some notes") {
    id
    notes …
Run Code Online (Sandbox Code Playgroud)

resolver amazon-web-services graphql aws-appsync aws-aurora

3
推荐指数
1
解决办法
934
查看次数

如何在Ivy中使用不会将工件复制到缓存的<filesystem>解析程序?

我有一个<filesystem>解析器ivysettings.xml,以及中央M2存储库,一切正常.但是,我想知道是否有办法完全绕过文件系统解析器找到的依赖项的缓存.我不需要在我的文件系统上多次使用它们(一次在解析器搜索的目录中,一次在缓存中,一次在每个项目的lib文件夹中......).

caching ivy resolver

2
推荐指数
1
解决办法
872
查看次数

如何在 JavaScript 中调试 GraphQL 解析器?

我正在关注howtographql.com上的教程,该教程创建了一个非常基本的 GraphQL 服务器,其中包含内存数据和用 JavaScript 编写的解析器。我一直遇到问题,我希望能够在解析器中放置一个断点,但是当我运行 GraphQL playground GUI 时,我在 DevTools 的 Sources 面板中看不到任何内容,并在其中添加了debugger一行代码也不会阻止它。

如何调试我的解析器?

架构

type Mutation {
  updateLink(id: ID!, url: String, description: String): Link
}
Run Code Online (Sandbox Code Playgroud)

解析器(我使用的是 immutable.js 的 Map;可能不正确)

let links = [
  {
    id: "link-0",
    url: "www.howtographql.com",
    description: "Fullstack tutorial for GraphQL",
  },
]

const resolvers = {
  Mutation: {
    updateLink(root, args) {
      const linkIndex = links.findIndex(link => link.id === args.id);
      const state = links.map(link => {
        debugger;
        if (link.id === args.id) { …
Run Code Online (Sandbox Code Playgroud)

javascript debugging resolver graphql

2
推荐指数
1
解决办法
5526
查看次数

遍历模板中的AWS Cloudformation资源阵列

从yml(或json)模板在AWS CloudFormation中创建资源时,是否可以在数组上进行迭代以使模板简短易读。例如,我有一个Appsync项目,在其中必须创建一堆几乎相同的AWS类型“ AWS :: AppSync :: Resolver”的解析器。在我用于Cloud Formation的YML模板中,1这样的资源可能看起来像这样

Resource:
 GraphQlAddPostsResolver:
      Type: "AWS::AppSync::Resolver"
      DependsOn: GraphQlSchema
      Properties:
        ApiId:
          Fn::GetAtt: [GraphQlApi, ApiId]
        TypeName: Mutation #<---
        FieldName: addPost #<----
        DataSourceName:
          Fn::GetAtt: [GraphQlLambdaDataSource, Name]
        RequestMappingTemplate: |
          {
              "version" : "2017-02-28",
              "operation": "Invoke",
              "payload": {
                  "field": "addPost", #<---
                  "context": $util.toJson($context)
              }
          }
        ResponseMappingTemplate: |
          $util.toJson($context.result)
Run Code Online (Sandbox Code Playgroud)

我可能有十几个或更多这些解析器,唯一的区别是我用表示的地方<----。有什么办法可以遍历一组值,比如

- Field: addPost
  Type: Mutation
- Field: allPosts
  Type: Query
- Field: getPost
  Type: Query
## etc...
Run Code Online (Sandbox Code Playgroud)

yaml resolver amazon-web-services aws-cloudformation aws-appsync

2
推荐指数
1
解决办法
3198
查看次数

角 6 | 只调用一次解析器

我的其中一个路由上有一个解析器,以允许它在页面实际加载之前获取数据。这需要多个请求,因此我使用的是rxjsfunction forkJoin。这将返回大量数据,并且在所有数据完全加载之前页面不会加载,这正是我想要的。

但是,获取的数据非常庞大,这意味着在路由加载之前可能需要一段时间。我想以某种方式,仍然解析这条路线,然后缓存它并让组件知道这是缓存的。

我依赖从activatedRoute组件内部返回的数据,因为页面需要它。所以我需要它停止覆盖当前存在的内容。

到目前为止,这是我的代码:

解析器:

const postId: string = this.postService.data.post.id;

const authorData$: Observable<HttpResponse<any>> = this.authorService.getAuthor();
const commentsData$: Observable<HttpResponse<any>> = this.commentsService.getComments();
Run Code Online (Sandbox Code Playgroud)

我知道这可以在一个请求中完成,但这只是我将使用它的一个例子。所以我不想要一个说把它放在一个请求中的建议。

this.activatedRoute.data.subscribe((data) => {
   this.author = data[0][0];
   this.comments = data[0][1].data;
});
Run Code Online (Sandbox Code Playgroud)

所以我只想在组件的第一次加载时执行此操作。

提前致谢。

routes resolver rxjs angular

2
推荐指数
1
解决办法
2127
查看次数